Merge remote-tracking branch 'upstream/master'

This commit is contained in:
S.Solodyagin
2025-07-02 20:54:46 +03:00
44 changed files with 1927 additions and 574 deletions
+24 -19
View File
@@ -51,7 +51,7 @@ func TestHelpOptionalArgs(t *testing.T) {
assert.NoError(t, err)
})
assert.True(t, exited)
expected := `Usage: test-app [<one> [<two>]] [flags]
expected := `Usage: test-app [<one> [<two>]]
Arguments:
[<one>] One optional arg.
@@ -71,6 +71,7 @@ func TestHelp(t *testing.T) {
Map map[string]int `help:"A map of strings to ints."`
Required bool `required help:"A required flag."`
Sort bool `negatable short:"s" help:"Is sortable or not."`
Approve bool `negatable:"deny" help:"Approve or deny message."`
One struct {
Flag string `help:"Nested flag."`
@@ -82,8 +83,7 @@ func TestHelp(t *testing.T) {
Three threeArg `arg help:"Sub-sub-arg."`
Four struct {
} `cmd help:"Sub-sub-command."`
Four struct{} `cmd help:"Sub-sub-command."`
} `cmd help:"Another subcommand."`
}
@@ -118,6 +118,7 @@ Flags:
--map=KEY=VALUE;... A map of strings to ints.
--required A required flag.
-s, --[no-]sort Is sortable or not.
--approve/deny Approve or deny message.
Commands:
one --required [flags]
@@ -159,6 +160,7 @@ Flags:
--map=KEY=VALUE;... A map of strings to ints.
--required A required flag.
-s, --[no-]sort Is sortable or not.
--approve/deny Approve or deny message.
--flag=STRING Nested flag under two.
--required-two
@@ -189,8 +191,7 @@ func TestFlagsLast(t *testing.T) {
Three threeArg `arg help:"Sub-sub-arg."`
Four struct {
} `cmd help:"Sub-sub-command."`
Four struct{} `cmd help:"Sub-sub-command."`
} `cmd help:"Another subcommand."`
}
@@ -293,8 +294,7 @@ func TestHelpTree(t *testing.T) {
Two struct {
Three threeArg `arg help:"Sub-sub-arg."`
Four struct {
} `cmd help:"Sub-sub-command." aliases:"for,fore"`
Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Another subcommand."`
}
@@ -320,7 +320,7 @@ func TestHelpTree(t *testing.T) {
assert.NoError(t, err)
})
assert.True(t, exited)
expected := `Usage: test-app <command> [flags]
expected := `Usage: test-app <command>
A test app.
@@ -353,7 +353,7 @@ Run "test-app <command> --help" for more information on a command.
assert.NoError(t, err)
})
assert.True(t, exited)
expected := `Usage: test-app one (un,uno) <command> [flags]
expected := `Usage: test-app one (un,uno) <command>
subcommand one
@@ -387,8 +387,7 @@ func TestHelpCompactNoExpand(t *testing.T) {
Two struct {
Three threeArg `arg help:"Sub-sub-arg."`
Four struct {
} `cmd help:"Sub-sub-command." aliases:"for,fore"`
Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Another subcommand."`
}
@@ -414,7 +413,7 @@ func TestHelpCompactNoExpand(t *testing.T) {
assert.NoError(t, err)
})
assert.True(t, exited)
expected := `Usage: test-app <command> [flags]
expected := `Usage: test-app <command>
A test app.
@@ -443,7 +442,7 @@ Run "test-app <command> --help" for more information on a command.
assert.NoError(t, err)
})
assert.True(t, exited)
expected := `Usage: test-app one (un,uno) <command> [flags]
expected := `Usage: test-app one (un,uno) <command>
subcommand one
@@ -600,7 +599,7 @@ func TestAutoGroup(t *testing.T) {
if node, ok := parent.(*kong.Node); ok {
return &kong.Group{
Key: node.Name,
Title: strings.Title(node.Name) + " flags:", //nolint
Title: strings.Title(node.Name) + " flags:", //nolint:staticcheck // strings.Title in test is okay
}
}
return nil
@@ -787,16 +786,17 @@ func TestUsageOnError(t *testing.T) {
Flag string `help:"A required flag." required`
}
w := &strings.Builder{}
exitCode := -1
p := mustNew(t, &cli,
kong.Writers(w, w),
kong.Description("Some description."),
kong.Exit(func(int) {}),
kong.Exit(func(code int) { exitCode = code }),
kong.UsageOnError(),
)
_, err := p.Parse([]string{})
p.FatalIfErrorf(err)
expected := `Usage: test --flag=STRING [flags]
expected := `Usage: test --flag=STRING
Some description.
@@ -807,6 +807,7 @@ Flags:
test: error: missing flags: --flag=STRING
`
assert.Equal(t, expected, w.String())
assert.Equal(t, 80, exitCode)
}
func TestShortUsageOnError(t *testing.T) {
@@ -814,22 +815,24 @@ func TestShortUsageOnError(t *testing.T) {
Flag string `help:"A required flag." required`
}
w := &strings.Builder{}
exitCode := -1
p := mustNew(t, &cli,
kong.Writers(w, w),
kong.Description("Some description."),
kong.Exit(func(int) {}),
kong.Exit(func(code int) { exitCode = code }),
kong.ShortUsageOnError(),
)
_, err := p.Parse([]string{})
assert.Error(t, err)
p.FatalIfErrorf(err)
expected := `Usage: test --flag=STRING [flags]
expected := `Usage: test --flag=STRING
Run "test --help" for more information.
test: error: missing flags: --flag=STRING
`
assert.Equal(t, expected, w.String())
assert.Equal(t, 80, exitCode)
}
func TestCustomShortUsageOnError(t *testing.T) {
@@ -841,10 +844,11 @@ func TestCustomShortUsageOnError(t *testing.T) {
fmt.Fprintln(ctx.Stdout, "🤷 wish I could help")
return nil
}
exitCode := -1
p := mustNew(t, &cli,
kong.Writers(w, w),
kong.Description("Some description."),
kong.Exit(func(int) {}),
kong.Exit(func(code int) { exitCode = code }),
kong.ShortHelp(shortHelp),
kong.ShortUsageOnError(),
)
@@ -857,4 +861,5 @@ func TestCustomShortUsageOnError(t *testing.T) {
test: error: missing flags: --flag=STRING
`
assert.Equal(t, expected, w.String())
assert.Equal(t, 80, exitCode)
}