Skip to content

Commit

Permalink
✨ feat(cflag,struct): add new util func IsGoodName, ParseTagValueQuick
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 19, 2023
1 parent 3699a1a commit 40ccfb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cflag/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import (
"github.com/gookit/color"
)

const (
// RegGoodName match a good option, argument name
RegGoodName = `^[a-zA-Z][\w-]*$`
)

var (
// GoodName good name for option and argument
goodName = regexp.MustCompile(RegGoodName)
)

// IsGoodName check
func IsGoodName(name string) bool {
return goodName.MatchString(name)
}

// IsZeroValue determines whether the string represents the zero
// value for a flag.
//
Expand Down
8 changes: 8 additions & 0 deletions structs/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ func ParseTagValueDefault(field, tagVal string) (mp maputil.SMap, err error) {
return
}

// ParseTagValueQuick quick parse tag value string by sep(;)
func ParseTagValueQuick(tagVal string, defines []string) maputil.SMap {
parseFn := ParseTagValueDefine(";", defines)

mp, _ := parseFn("", tagVal)
return mp
}

// ParseTagValueDefine parse tag value string by given defines.
//
// Examples:
Expand Down

0 comments on commit 40ccfb8

Please sign in to comment.