Add shared report format flag
This commit is contained in:
@@ -67,14 +67,14 @@ func TestParserFailuresRetainAliasUsageAndFlagSpellings(t *testing.T) {
|
||||
command := NewCommand(CommandSpec[struct{}]{
|
||||
Name: "inspect",
|
||||
NewInput: func() struct{} { built++; return struct{}{} },
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "format"}, (*string)(nil),
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "style"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil },
|
||||
func(*struct{}, Supplied[string]) {})},
|
||||
Run: func(Invocation, struct{}) Outcome { t.Fatal("invalid input executed"); return Success() },
|
||||
})
|
||||
app, err := New(Identity{Name: "Demo"}, command, Alias("i", "inspect"),
|
||||
FlagAliasFor("inspect", "--fmt", "--format"),
|
||||
FlagAliasFor("inspect", "-F", "--format"), FlagAlias("--hlep", "--help"))
|
||||
FlagAliasFor("inspect", "--fmt", "--style"),
|
||||
FlagAliasFor("inspect", "-F", "--style"), FlagAlias("--hlep", "--help"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func TestCommandContextSurvivesIncompleteAndInvalidOperandCounts(t *testing.T) {
|
||||
usage bool
|
||||
}{
|
||||
{name: "interspersed alias", args: []string{"first", "--fmt=yaml", "second"}},
|
||||
{name: "interspersed canonical flag", args: []string{"first", "--format=yaml", "second"}},
|
||||
{name: "interspersed canonical flag", args: []string{"first", "--style=yaml", "second"}},
|
||||
{name: "partial help", args: []string{"first", "--help"}, help: true},
|
||||
{name: "partial help with flag alias", args: []string{"first", "--fmt=yaml", "--help"}, help: true},
|
||||
{name: "excess operands", args: []string{"first", "second", "third", "--fmt=yaml"}, usage: true},
|
||||
@@ -125,7 +125,7 @@ func TestCommandContextSurvivesIncompleteAndInvalidOperandCounts(t *testing.T) {
|
||||
built, ran := 0, false
|
||||
command := NewCommand(CommandSpec[input]{
|
||||
Name: "run", NewInput: func() input { built++; return input{} },
|
||||
Flags: []Flag[input]{ValueFlag(FlagMeta{Name: "format"}, (*string)(nil),
|
||||
Flags: []Flag[input]{ValueFlag(FlagMeta{Name: "style"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil },
|
||||
func(target *input, value Supplied[string]) { target.format = value })},
|
||||
Arguments: []Argument[input]{RepeatArgument(ArgumentMeta{Name: "ARG"}, 2, 2,
|
||||
@@ -142,7 +142,7 @@ func TestCommandContextSurvivesIncompleteAndInvalidOperandCounts(t *testing.T) {
|
||||
return Success()
|
||||
},
|
||||
})
|
||||
app, err := New(Identity{Name: "Demo"}, command, Alias("r", "run"), FlagAliasFor("run", "--fmt", "--format"))
|
||||
app, err := New(Identity{Name: "Demo"}, command, Alias("r", "run"), FlagAliasFor("run", "--fmt", "--style"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func TestCommandContextSurvivesIncompleteAndInvalidOperandCounts(t *testing.T) {
|
||||
} else if outcome.Kind != OutcomeSuccess {
|
||||
t.Fatalf("outcome = %#v, diagnostics %q", outcome, diagnostics.String())
|
||||
}
|
||||
if test.help && (!strings.Contains(output.String(), "Demo "+spelling+" ARG") || !strings.Contains(output.String(), "--fmt → --format")) {
|
||||
if test.help && (!strings.Contains(output.String(), "Demo "+spelling+" ARG") || !strings.Contains(output.String(), "--fmt → --style")) {
|
||||
t.Errorf("command help = %q", output.String())
|
||||
}
|
||||
if test.help || test.usage {
|
||||
@@ -229,13 +229,13 @@ func TestDiscoveryHelpComposesGroupShortcutsAndOverrides(t *testing.T) {
|
||||
initialized := false
|
||||
inspect := NewCommand(CommandSpec[struct{}]{
|
||||
Name: "inspect", NewInput: func() struct{} { initialized = true; return struct{}{} },
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "format"}, (*string)(nil),
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "style"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil }, func(*struct{}, Supplied[string]) {})},
|
||||
Run: func(Invocation, struct{}) Outcome { return Success() },
|
||||
})
|
||||
declarations := []Declaration{Group("box", "Box"), inspect, simpleRunnable("alternate"),
|
||||
Alias("pk", "box"), Alias("box admin pick", "inspect"), Alias("box admin other", "inspect"),
|
||||
FlagAlias("--hlep", "--help"), FlagAliasFor("inspect", "--fmt", "--format")}
|
||||
FlagAlias("--hlep", "--help"), FlagAliasFor("inspect", "--fmt", "--style")}
|
||||
wantPick := "pick → inspect"
|
||||
if override {
|
||||
declarations = append(declarations, Alias("pk admin pick", "alternate"), Alias("pk admin nested choose", "inspect"))
|
||||
@@ -308,7 +308,7 @@ func TestHelpDiscoversRoutesThroughIntermediateAliases(t *testing.T) {
|
||||
makeCommand := func(name string) Command {
|
||||
return NewCommand(CommandSpec[struct{}]{
|
||||
Name: name, NewInput: func() struct{} { built++; return struct{}{} },
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "format"}, (*string)(nil),
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "style"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil }, func(*struct{}, Supplied[string]) {})},
|
||||
Run: func(inv Invocation, _ struct{}) Outcome {
|
||||
runs++
|
||||
@@ -327,7 +327,7 @@ func TestHelpDiscoversRoutesThroughIntermediateAliases(t *testing.T) {
|
||||
}
|
||||
declarations := []Declaration{group, makeCommand("inspect"), makeCommand("alternate"),
|
||||
Alias("p", "q"), Alias("q", target), Alias(middle+" pick", "inspect"), Alias(middle+" other", "inspect"),
|
||||
FlagAlias("--hlep", "--help"), FlagAliasFor("inspect", "--fmt", "--format")}
|
||||
FlagAlias("--hlep", "--help"), FlagAliasFor("inspect", "--fmt", "--style")}
|
||||
wantTarget := "inspect"
|
||||
if test.override {
|
||||
declarations = append(declarations, Alias(prefix+" pick", "alternate"))
|
||||
@@ -352,7 +352,7 @@ func TestHelpDiscoversRoutesThroughIntermediateAliases(t *testing.T) {
|
||||
t.Errorf("help %q omits %q", output.String(), fragment)
|
||||
}
|
||||
}
|
||||
if strings.Contains(output.String(), "--fmt") || strings.Contains(output.String(), "--format") ||
|
||||
if strings.Contains(output.String(), "--fmt") || strings.Contains(output.String(), "--style") ||
|
||||
(test.override && strings.Contains(output.String(), "pick → inspect")) {
|
||||
t.Errorf("help exposes a descendant flag or overridden destination: %q", output.String())
|
||||
}
|
||||
@@ -920,7 +920,7 @@ func TestAliasHelpTargetsGroupsAndDiscoveryViews(t *testing.T) {
|
||||
inputBuilds++
|
||||
return struct{}{}
|
||||
},
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "format"}, (*string)(nil),
|
||||
Flags: []Flag[struct{}]{ValueFlag(FlagMeta{Name: "style"}, (*string)(nil),
|
||||
func(value string) (string, error) { return value, nil },
|
||||
func(*struct{}, Supplied[string]) {},
|
||||
)},
|
||||
@@ -939,7 +939,7 @@ func TestAliasHelpTargetsGroupsAndDiscoveryViews(t *testing.T) {
|
||||
Alias("pk", "promptkit"),
|
||||
Alias("pk list bundles", "promptkit show prompt"),
|
||||
FlagAlias("--hlep", "--help"),
|
||||
FlagAliasFor("promptkit show prompt", "--fmt", "--format"),
|
||||
FlagAliasFor("promptkit show prompt", "--fmt", "--style"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -985,13 +985,13 @@ func TestAliasHelpTargetsGroupsAndDiscoveryViews(t *testing.T) {
|
||||
{
|
||||
name: "scoped flag alias appears on canonical command help",
|
||||
args: []string{"promptkit", "show", "prompt", "--hlep"},
|
||||
want: []string{"--fmt → --format"},
|
||||
want: []string{"--fmt → --style"},
|
||||
},
|
||||
{
|
||||
name: "group excludes descendant scoped flag aliases",
|
||||
args: []string{"promptkit", "--help"},
|
||||
want: []string{"Command Aliases:"},
|
||||
omit: []string{"--fmt → --format"},
|
||||
omit: []string{"--fmt → --style"},
|
||||
},
|
||||
{
|
||||
name: "root lists explicit command aliases separately",
|
||||
|
||||
Reference in New Issue
Block a user