flags : can check for both Flag types because the value.FieldByName().Type() can be printed

This commit is contained in:
bth 2026-01-18 18:29:34 -08:00
commit 0d32446986
4 changed files with 10 additions and 15 deletions

View file

@ -71,14 +71,16 @@ func Help(subcmd string, opts any) {
case Arg: case Arg:
positional += fmt.Sprintf(" [%s]", strings.ToLower(field.Name)) positional += fmt.Sprintf(" [%s]", strings.ToLower(field.Name))
fmt.Fprintf(w, "[%v]\tstring\t%v\n", strings.ToLower(field.Name), value.FieldByName("Help")) fmt.Fprintf(w, "[%v]\tstring\t%v\n", strings.ToLower(field.Name), value.FieldByName("Help"))
case Flag[string]: case Flag[string], Flag[bool]:
positional += fmt.Sprintf(" [%s]", value.FieldByName("Long"))
fmt.Fprintf(w, "%v | %v\tstring\t%v\n", value.FieldByName("Long"), value.FieldByName("Short"), value.FieldByName("Help"))
case Flag[bool]:
if field.Name != "Help" { if field.Name != "Help" {
positional += fmt.Sprintf(" [%s]", value.FieldByName("Long")) positional += fmt.Sprintf(" [%s]", value.FieldByName("Long"))
} }
fmt.Fprintf(w, "%v | %v\tbool\t%v\n", value.FieldByName("Long"), value.FieldByName("Short"), value.FieldByName("Help")) fmt.Fprintf(w, "%v | %v\t%v\t%v\n",
value.FieldByName("Long"),
value.FieldByName("Short"),
value.FieldByName("Val").Type(),
value.FieldByName("Help"),
)
} }
} }
fmt.Printf("um %s%s\n", subcmd, positional) fmt.Printf("um %s%s\n", subcmd, positional)

View file

@ -41,6 +41,5 @@ func parseArgs(args []string) options {
} }
func Next(args []string) { func Next(args []string) {
opts := parseArgs(args) _ = parseArgs(args)
fmt.Println(opts)
} }

View file

@ -1,8 +1,6 @@
package sort package sort
import ( import (
"fmt"
"github.com/brtholomy/um/go/flags" "github.com/brtholomy/um/go/flags"
) )
@ -45,6 +43,5 @@ func parseArgs(args []string) options {
} }
func Sort(args []string) { func Sort(args []string) {
opts := parseArgs(args) _ = parseArgs(args)
fmt.Println(opts)
} }

View file

@ -1,8 +1,6 @@
package tag package tag
import ( import (
"fmt"
"github.com/brtholomy/um/go/flags" "github.com/brtholomy/um/go/flags"
) )
@ -45,6 +43,5 @@ func parseArgs(args []string) options {
} }
func Tag(args []string) { func Tag(args []string) {
opts := parseArgs(args) _ = parseArgs(args)
fmt.Println(opts)
} }