diff --git a/defaultActions_test.go b/defaultActions_test.go index 0ed25717..be760165 100644 --- a/defaultActions_test.go +++ b/defaultActions_test.go @@ -39,7 +39,7 @@ func TestActionFlags(t *testing.T) { cmd.Flag("alpha").Changed = true a := actionFlags(cmd).Invoke(Context{Value: "-a"}) - assertEqual(t, ActionValuesDescribed("b", "", "h", "help for this command").Tag("flags").NoSpace('b', 'h').Invoke(Context{}).Prefix("-a"), a) + assertEqual(t, ActionValuesDescribed("b", "", "h", "help for this command").Tag("shorthand flags").NoSpace('b', 'h').Invoke(Context{}).Prefix("-a"), a) } func TestActionExecCommandEnv(t *testing.T) { diff --git a/example-nonposix/cmd/root_test.go b/example-nonposix/cmd/root_test.go index 1f03a5d2..066591be 100644 --- a/example-nonposix/cmd/root_test.go +++ b/example-nonposix/cmd/root_test.go @@ -26,7 +26,7 @@ func TestInterspersed(t *testing.T) { "-delim-slash", "OptargDelimiter '/'", ).NoSpace('.'). Style(style.Yellow). - Tag("flags")) + Tag("shorthand flags")) s.Run("-delim-colon:d1", "positional1", "-d"). Expect(carapace.ActionValues()) @@ -49,11 +49,15 @@ func TestRoot(t *testing.T) { Usage("OptargDelimiter '/'")) s.Run("-c"). - Expect(carapace.ActionValuesDescribed( - "-c", "CountN", - "-count", "CountN"). - NoSpace('.'). - Tag("flags")) + Expect(carapace.Batch( + carapace.ActionValuesDescribed( + "-c", "CountN", + ).Tag("shorthand flags"), + carapace.ActionValuesDescribed( + "-count", "CountN", + ).Tag("longhand flags"), + ).ToA(). + NoSpace('.')) }) } @@ -68,11 +72,15 @@ func TestNargs(t *testing.T) { Usage("Nargs")) s.Run("--nargs-any", "na2", "-c"). - Expect(carapace.ActionValuesDescribed( - "-c", "CountN", - "-count", "CountN"). - NoSpace('.'). - Tag("flags")) + Expect(carapace.Batch( + carapace.ActionValuesDescribed( + "-c", "CountN", + ).Tag("shorthand flags"), + carapace.ActionValuesDescribed( + "-count", "CountN", + ).Tag("longhand flags"), + ).ToA(). + NoSpace('.')) s.Run("--nargs-any", "na1", "na2", ""). Expect(carapace.ActionValues("na3"). @@ -99,6 +107,6 @@ func TestNargs(t *testing.T) { "--nargs-two", "Nargs"). Style(style.Magenta). NoSpace('.'). - Tag("flags")) + Tag("longhand flags")) }) } diff --git a/example/cmd/action_test.go b/example/cmd/action_test.go index 4e80ec68..3e288319 100644 --- a/example/cmd/action_test.go +++ b/example/cmd/action_test.go @@ -212,15 +212,19 @@ func TestDash(t *testing.T) { Usage("action [pos1] [pos2] [--] [dashAny]...")) s.Run("action", "--", "-"). - Expect(carapace.ActionStyledValuesDescribed( - "--embedded-bool", "embedded bool flag", style.Default, - "--embedded-optarg", "embedded optarg flag", style.Yellow, - "--embedded-string", "embedded string flag", style.Blue, - "-h", "help for embedded", style.Default, - "--help", "help for embedded", style.Default). + Expect(carapace.Batch( + carapace.ActionStyledValuesDescribed( + "-h", "help for embedded", style.Default, + ).Tag("shorthand flags"), + carapace.ActionStyledValuesDescribed( + "--embedded-bool", "embedded bool flag", style.Default, + "--embedded-optarg", "embedded optarg flag", style.Yellow, + "--embedded-string", "embedded string flag", style.Blue, + "--help", "help for embedded", style.Default, + ).Tag("longhand flags"), + ).ToA(). NoSpace('.'). - Usage("action [pos1] [pos2] [--] [dashAny]..."). - Tag("flags")) + Usage("action [pos1] [pos2] [--] [dashAny]...")) s.Run("action", "--", "--"). Expect(carapace.ActionStyledValuesDescribed( @@ -230,7 +234,7 @@ func TestDash(t *testing.T) { "--help", "help for embedded", style.Default). NoSpace('.'). Usage("action [pos1] [pos2] [--] [dashAny]..."). - Tag("flags")) + Tag("longhand flags")) s.Run("action", "--", "embeddedP1", "--embedded-optarg="). Expect(carapace.ActionValues("eo1", "eo2", "eo3"). diff --git a/example/cmd/chain_test.go b/example/cmd/chain_test.go index c36d161b..a273058b 100644 --- a/example/cmd/chain_test.go +++ b/example/cmd/chain_test.go @@ -17,7 +17,7 @@ func TestShorthandChain(t *testing.T) { "v", style.Blue, ).Prefix("-b"). NoSpace('c', 'o'). - Tag("flags")) + Tag("shorthand flags")) s.Run("chain", "-bc"). Expect(carapace.ActionStyledValues( @@ -26,7 +26,7 @@ func TestShorthandChain(t *testing.T) { "v", style.Blue, ).Prefix("-bc"). NoSpace('c', 'o'). - Tag("flags")) + Tag("shorthand flags")) s.Run("chain", "-bcc"). Expect(carapace.ActionStyledValues( @@ -35,7 +35,7 @@ func TestShorthandChain(t *testing.T) { "v", style.Blue, ).Prefix("-bcc"). NoSpace('c', 'o'). - Tag("flags")) + Tag("shorthand flags")) s.Run("chain", "-bcco"). Expect(carapace.ActionStyledValues( @@ -43,7 +43,7 @@ func TestShorthandChain(t *testing.T) { "v", style.Blue, ).Prefix("-bcco"). NoSpace('c'). - Tag("flags")) + Tag("shorthand flags")) s.Run("chain", "-bcco", ""). Expect(carapace.ActionValues( @@ -75,6 +75,6 @@ func TestShorthandChain(t *testing.T) { "o", style.Yellow, ).Prefix("-c"). NoSpace('c', 'o'). - Tag("flags")) + Tag("shorthand flags")) }) } diff --git a/example/cmd/interspersed_test.go b/example/cmd/interspersed_test.go index d8a37bbe..1b848859 100644 --- a/example/cmd/interspersed_test.go +++ b/example/cmd/interspersed_test.go @@ -16,7 +16,7 @@ func TestInterspersed(t *testing.T) { ). StyleR(&style.Carapace.FlagArg). NoSpace('.'). - Tag("flags")) + Tag("longhand flags")) s.Run("interspersed", "--bool", "--s"). Expect(carapace.ActionValuesDescribed( @@ -24,7 +24,7 @@ func TestInterspersed(t *testing.T) { ). StyleR(&style.Carapace.FlagArg). NoSpace('.'). - Tag("flags")) + Tag("longhand flags")) s.Run("interspersed", "--bool", ""). Expect(carapace.ActionValues( diff --git a/example/cmd/modifier_test.go b/example/cmd/modifier_test.go index b9c3406d..97d35c38 100644 --- a/example/cmd/modifier_test.go +++ b/example/cmd/modifier_test.go @@ -323,7 +323,7 @@ func TestSplit(t *testing.T) { Suffix(" "). NoSpace('*'). Usage("Split()"). - Tag("flags")) + Tag("longhand flags")) s.Run("modifier", "--split", "pos1 --bool="). Expect(carapace.ActionStyledValues( @@ -405,7 +405,7 @@ func TestSplitP(t *testing.T) { ).NoSpace('*'). Prefix("pos1>subdir/file1.txt "). Suffix(" "). - Tag("flags"). + Tag("longhand flags"). Usage("SplitP()")) s.Run("modifier", "--splitp", "pos1 1>"). diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go index be6f72ed..8f2f74b0 100644 --- a/example/cmd/root_test.go +++ b/example/cmd/root_test.go @@ -96,21 +96,25 @@ func TestRoot(t *testing.T) { ).Tag("main commands")) s.Run("-"). - Expect(carapace.ActionStyledValuesDescribed( - "--chdir", "change work directory", style.Blue, - "-C", "change work directory", style.Blue, - "--array", "multiflag", style.Blue, - "-a", "multiflag", style.Blue, - "-h", "help for example", style.Default, - "--help", "help for example", style.Default, - "--persistentFlag", "Help message for persistentFlag", style.Yellow, - "--persistentFlag2", "Help message for persistentFlag2", style.Blue, - "-p", "Help message for persistentFlag", style.Yellow, - "--toggle", "Help message for toggle", style.Default, - "-t", "Help message for toggle", style.Default, - "-v", "version for example", style.Default, - "--version", "version for example", style.Default, - ).NoSpace('.').Tag("flags")) + Expect(carapace.Batch( + carapace.ActionStyledValuesDescribed( + "-C", "change work directory", style.Blue, + "-a", "multiflag", style.Blue, + "-h", "help for example", style.Default, + "-p", "Help message for persistentFlag", style.Yellow, + "-t", "Help message for toggle", style.Default, + "-v", "version for example", style.Default, + ).Tag("shorthand flags"), + carapace.ActionStyledValuesDescribed( + "--chdir", "change work directory", style.Blue, + "--array", "multiflag", style.Blue, + "--help", "help for example", style.Default, + "--persistentFlag", "Help message for persistentFlag", style.Yellow, + "--persistentFlag2", "Help message for persistentFlag2", style.Blue, + "--toggle", "Help message for toggle", style.Default, + "--version", "version for example", style.Default, + ).Tag("longhand flags"), + ).ToA().NoSpace('.')) s.Run("--"). Expect(carapace.ActionStyledValuesDescribed( @@ -121,27 +125,27 @@ func TestRoot(t *testing.T) { "--persistentFlag2", "Help message for persistentFlag2", style.Blue, "--toggle", "Help message for toggle", style.Default, "--version", "version for example", style.Default, - ).NoSpace('.').Tag("flags")) + ).NoSpace('.').Tag("longhand flags")) s.Run("--a"). Expect(carapace.ActionStyledValuesDescribed( "--array", "multiflag", style.Blue, - ).NoSpace('.').Tag("flags")) + ).NoSpace('.').Tag("longhand flags")) s.Run("--array"). Expect(carapace.ActionStyledValuesDescribed( "--array", "multiflag", style.Blue, - ).NoSpace('.').Tag("flags")) + ).NoSpace('.').Tag("longhand flags")) s.Run("--array", "", "--a"). Expect(carapace.ActionStyledValuesDescribed( "--array", "multiflag", style.Blue, - ).NoSpace('.').Tag("flags")) + ).NoSpace('.').Tag("longhand flags")) s.Run("-a", "", "--a"). Expect(carapace.ActionStyledValuesDescribed( "--array", "multiflag", style.Blue, - ).NoSpace('.').Tag("flags")) + ).NoSpace('.').Tag("longhand flags")) }) } diff --git a/internalActions.go b/internalActions.go index f363f24e..5469db55 100644 --- a/internalActions.go +++ b/internalActions.go @@ -83,7 +83,7 @@ func actionFlags(cmd *cobra.Command) Action { isShorthandSeries := flagSet.IsShorthandSeries(c.Value) nospace := make([]rune, 0) - vals := make([]string, 0) + batch := Batch() flagSet.VisitAll(func(f *pflagfork.Flag) { switch { case f.Hidden && !env.Hidden(): @@ -103,7 +103,7 @@ func actionFlags(cmd *cobra.Command) Action { return // abort shorthand flag series if a previous one is not bool or count and requires an argument (no default value) } } - vals = append(vals, f.Shorthand, f.Usage, f.Style()) + batch = append(batch, ActionStyledValuesDescribed(f.Shorthand, f.Usage, f.Style()).Tag("shorthand flags")) if f.IsOptarg() { nospace = append(nospace, []rune(f.Shorthand)[0]) } @@ -111,25 +111,25 @@ func actionFlags(cmd *cobra.Command) Action { } else { switch f.Mode() { case pflagfork.NameAsShorthand: - vals = append(vals, "-"+f.Name, f.Usage, f.Style()) + batch = append(batch, ActionStyledValuesDescribed("-"+f.Name, f.Usage, f.Style()).Tag("longhand flags")) case pflagfork.Default: - vals = append(vals, "--"+f.Name, f.Usage, f.Style()) + batch = append(batch, ActionStyledValuesDescribed("--"+f.Name, f.Usage, f.Style()).Tag("longhand flags")) } if f.Shorthand != "" && f.ShorthandDeprecated == "" { - vals = append(vals, "-"+f.Shorthand, f.Usage, f.Style()) + batch = append(batch, ActionStyledValuesDescribed("-"+f.Shorthand, f.Usage, f.Style()).Tag("shorthand flags")) } } }) if isShorthandSeries { if len(nospace) > 0 { - return ActionStyledValuesDescribed(vals...).Prefix(c.Value).NoSpace(nospace...) + return batch.ToA().Prefix(c.Value).NoSpace(nospace...) } - return ActionStyledValuesDescribed(vals...).Prefix(c.Value) + return batch.ToA().Prefix(c.Value) } - return ActionStyledValuesDescribed(vals...).MultiParts(".") // multiparts completion for flags grouped with `.` - }).Tag("flags") + return batch.ToA().MultiParts(".") // multiparts completion for flags grouped with `.` + }) } func initHelpCompletion(cmd *cobra.Command) { diff --git a/pkg/sandbox/sandbox_test.go b/pkg/sandbox/sandbox_test.go index 85231c6c..8d3d21d8 100644 --- a/pkg/sandbox/sandbox_test.go +++ b/pkg/sandbox/sandbox_test.go @@ -83,14 +83,14 @@ func TestPreRun(t *testing.T) { Expect(carapace.ActionValuesDescribed( "--root", "root flag"). NoSpace('.'). - Tag("flags")) + Tag("longhand flags")) s.Run("--root", "sub", "--"). Expect(carapace.ActionStyledValuesDescribed( "--help", "help for sub", style.Default, "--sub", "sub flag", style.Blue). NoSpace('.'). - Tag("flags")) + Tag("longhand flags")) s.Run("--root", "sub", "--sub", ""). Expect(carapace.ActionValues("true").