diff --git a/flags/flags.go b/flags/flags.go index 5e40ae8..8bc1846 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -10,18 +10,16 @@ type Arg struct { Help string } -type Flag struct { - Long string - Short string - Val string - Help string +// type constraint +type Val interface { + string | bool } -// there's got to be a way to generalize the val field to string|bool -type FlagBool struct { +// with generic Val field, instantiate like Flag[string] +type Flag[V Val] struct { Long string Short string - Val bool + Val V Help string } diff --git a/go b/go new file mode 100755 index 0000000..7a363ee Binary files /dev/null and b/go differ diff --git a/tag/tag.go b/tag/tag.go index 3ef2534..231956c 100644 --- a/tag/tag.go +++ b/tag/tag.go @@ -8,15 +8,15 @@ import ( type options struct { query flags.Arg - date flags.Flag - invert flags.FlagBool + date flags.Flag[string] + invert flags.Flag[bool] } func InitOpts() options { return options{ flags.Arg{"", "tag query"}, - flags.Flag{"--date", "-d", "", "date range"}, - flags.FlagBool{"--invert", "-i", false, "invert match"}, + flags.Flag[string]{"--date", "-d", "", "date range"}, + flags.Flag[bool]{"--invert", "-i", false, "invert match"}, } } @@ -25,14 +25,14 @@ func ParseArgs(args []string) options { if len(args) == 0 { return opts } - if flags.HasDashPrefix(args[0]) { + if !flags.HasDashPrefix(args[0]) { opts.query.Val = args[0] } for i, arg := range args { switch arg { case opts.invert.Long, opts.invert.Short: opts.invert.Val = true - case opts.date.Long: + case opts.date.Long, opts.date.Short: if flags.MissingValueArg(args, i) { flags.HelpMissingVal(arg) break