improve package gcmd/gtag

This commit is contained in:
John Guo
2021-12-10 23:58:10 +08:00
parent 34e7913268
commit f0c25d8476
2 changed files with 10 additions and 0 deletions

View File

@ -57,6 +57,9 @@ func NewFromObject(object interface{}) (rootCmd *Command, err error) {
rootCommandName = gmeta.Get(object, tagNameRoot).String()
subCommands []*Command
)
if rootCommandName == "" {
rootCommandName = rootCmd.Name
}
for i := 0; i < originValueAndKind.InputValue.NumMethod(); i++ {
var (
method = originValueAndKind.InputValue.Method(i)

View File

@ -10,6 +10,7 @@
package gtag
import (
"fmt"
"regexp"
"sync"
)
@ -24,6 +25,9 @@ var (
func Set(name, value string) {
mu.Lock()
defer mu.Unlock()
if _, ok := data[name]; ok {
panic(fmt.Sprintf(`value for tag "%s" already exists`, name))
}
data[name] = value
}
@ -32,6 +36,9 @@ func Sets(m map[string]string) {
mu.Lock()
defer mu.Unlock()
for k, v := range m {
if _, ok := data[k]; ok {
panic(fmt.Sprintf(`value for tag "%s" already exists`, k))
}
data[k] = v
}
}