Display usage information on error.

This commit is contained in:
Alec Thomas
2018-06-21 10:08:01 +10:00
parent d9c0dd25b1
commit cdcdf49f67
7 changed files with 53 additions and 16 deletions
+5
View File
@@ -23,6 +23,7 @@ type Tag struct {
Short rune
Hidden bool
Sep rune
Enum map[string]bool
// Storage for all tag keys for arbitrary lookups.
items map[string]string
@@ -112,6 +113,7 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
s, chars := getTagInfo(ft)
t := &Tag{
items: parseTagItems(s, chars),
Enum: map[string]bool{},
}
t.Cmd = t.Has("cmd")
t.Arg = t.Has("arg")
@@ -141,6 +143,9 @@ func parseTag(fv reflect.Value, ft reflect.StructField) *Tag {
if t.PlaceHolder == "" {
t.PlaceHolder = strings.ToUpper(dashedString(fv.Type().Name()))
}
for _, part := range strings.Split(t.Get("enum"), ",") {
t.Enum[part] = true
}
return t
}