Skip to content

Commit

Permalink
fix: ignore unexported fields
Browse files Browse the repository at this point in the history
chore: upgrade ecp to v0.2.3
  • Loading branch information
shaun.fu committed Nov 16, 2023
1 parent 87622fa commit a4b1d5f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/wrfly/gua

go 1.12

require github.com/wrfly/ecp v0.2.0
require github.com/wrfly/ecp v0.2.3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/wrfly/ecp v0.2.0 h1:nfPa9FMAOvn3mgwDOAr+0f8thaCzpN/FBpBJdQNpM4I=
github.com/wrfly/ecp v0.2.0/go.mod h1:cmmFTD+MLlrDa3/EO3gjeKLKUhHiYP3cgaaJamIS1NU=
github.com/wrfly/ecp v0.2.3 h1:yTCwNVq8L5aOFCrTf5kyFZsihQYUHASz1Zr/w78JENI=
github.com/wrfly/ecp v0.2.3/go.mod h1:8rt/LxDJNLd6AxL56hbbbNWZfJLK4x8+UU4Fyey0m+8=
25 changes: 11 additions & 14 deletions gua.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@ type gua struct {
f *flag.FlagSet
}

func firstKeyLower(s string) string {
if s == "" {
return s
}
return strings.ToLower(string(s[0])) + s[1:]
}
func (g *gua) getKey(structure, field string, tag reflect.StructTag) string {
structure = strings.ToLower(structure)
field = strings.ToLower(field)

func (g *gua) getKey(pName, sName string, tag reflect.StructTag) string {
desc := tag.Get("desc")
key := tag.Get("name")
pName = firstKeyLower(pName)
sName = firstKeyLower(sName)
if key == "" {
if pName == "" {
key = sName
if key == "-" { // ignore this key
return ""
}
if key == "" && field != "" {
if structure == "" {
key = field
} else {
key = pName + "." + sName
key = structure + "." + field
}
}
desc := tag.Get("desc")
if desc != "" {
key += splitter + desc
}
Expand Down

0 comments on commit a4b1d5f

Please sign in to comment.