flags pkg : but im not convinced this is right

This commit is contained in:
bth 2026-01-17 20:21:37 -08:00
commit f483e08105
4 changed files with 57 additions and 48 deletions

24
flags/flags.go Normal file
View file

@ -0,0 +1,24 @@
package flags
import (
"fmt"
"strings"
)
type Flag string
func (f Flag) Dash() string {
return fmt.Sprintf("--%s", f)
}
// prepend --flag to args if a flag isn't there:
// allows trailing flags:
// um tag foo --invert
// becomes:
// um tag --query foo --invert
func PrependFlagToArgs(args []string, flag Flag) []string {
if len(args) >= 1 && !strings.HasPrefix(args[0], "-") {
args = append([]string{flag.Dash()}, args...)
}
return args
}