command: hard wrap help message flags
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m51s
Test / Hakurei (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 5m53s
Test / Hakurei (race detector) (push) Successful in 7m2s
Test / ShareFS (push) Successful in 7m19s
Test / Flake checks (push) Successful in 1m8s

This greatly improves readability when lots of flags are registered.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-08-07 20:32:24 +09:00
parent b37c1d8993
commit f1dd3a085b
6 changed files with 58 additions and 36 deletions
+18 -22
View File
@@ -70,7 +70,7 @@ func TestParse(t *testing.T) {
"d=0 out of order string flag",
buildTestCommand,
[]string{"string", "--string", "64d3b4b7b21788585845060e2199a78f"},
"flag provided but not defined: -string\n\nUsage:\ttest string [-h | --help] COMMAND [OPTIONS]\n\n", "",
"flag provided but not defined: -string\nusage: test string [-h | --help] <command> [<args>]\n\n", "",
errors.New("flag provided but not defined: -string"),
},
{
@@ -120,7 +120,7 @@ func TestParse(t *testing.T) {
"d=1 empty sub help",
buildTestCommand,
[]string{"empty", "-h"},
"\nUsage:\ttest empty [-h | --help] COMMAND [OPTIONS]\n\n", "", flag.ErrHelp,
"usage: test empty [-h | --help] <command> [<args>]\n\n", "", flag.ErrHelp,
},
{
"d=1 no match",
@@ -151,10 +151,10 @@ func TestParse(t *testing.T) {
"d=0 help",
buildTestCommand,
[]string{},
`
Usage: test [-h | --help] [-v] [--fail] [--string <value>] [--int <int>] [--repeat <value>] COMMAND [OPTIONS]
`usage: test [-h | --help] [-v] [--fail] [--string <value>] [--int <int>]
[--repeat <value>] <command> [<args>]
Commands:
commands:
error return an error
print wraps Fprint
string print string passed by flag
@@ -171,10 +171,10 @@ Commands:
"d=0 help flag",
buildTestCommand,
[]string{"-h"},
`
Usage: test [-h | --help] [-v] [--fail] [--string <value>] [--int <int>] [--repeat <value>] COMMAND [OPTIONS]
`usage: test [-h | --help] [-v] [--fail] [--string <value>] [--int <int>]
[--repeat <value>] <command> [<args>]
Commands:
commands:
error return an error
print wraps Fprint
string print string passed by flag
@@ -185,7 +185,7 @@ Commands:
succeed this command succeeds
deep top level of command tree with various levels
Flags:
flags:
-fail
fail early
-int int
@@ -203,10 +203,9 @@ Flags:
"d=1 help",
buildTestCommand,
[]string{"join"},
`
Usage: test join [-h | --help] COMMAND [OPTIONS]
`usage: test join [-h | --help] <command> [<args>]
Commands:
commands:
out write result to wout
log log result to wlog
@@ -216,10 +215,9 @@ Commands:
"d=1 help flag",
buildTestCommand,
[]string{"join", "-h"},
`
Usage: test join [-h | --help] COMMAND [OPTIONS]
`usage: test join [-h | --help] <command> [<args>]
Commands:
commands:
out write result to wout
log log result to wlog
@@ -230,10 +228,9 @@ Commands:
"d=2 help",
buildTestCommand,
[]string{"deep", "d=2"},
`
Usage: test deep d=2 [-h | --help] COMMAND [OPTIONS]
`usage: test deep d=2 [-h | --help] <command> [<args>]
Commands:
commands:
d=3 relative third level
`, "", command.ErrHelp,
@@ -242,10 +239,9 @@ Commands:
"d=2 help flag",
buildTestCommand,
[]string{"deep", "d=2", "-h"},
`
Usage: test deep d=2 [-h | --help] COMMAND [OPTIONS]
`usage: test deep d=2 [-h | --help] <command> [<args>]
Commands:
commands:
d=3 relative third level
`, "", flag.ErrHelp,
@@ -261,7 +257,7 @@ Commands:
t.Errorf("Parse: error = %v; wantErr %v", err, tc.wantErr)
}
if got := wout.String(); got != tc.want {
t.Errorf("Parse: %s want %s", got, tc.want)
t.Errorf("Parse:\n%s\nwant\n%s", got, tc.want)
}
if gotLog := wlog.String(); gotLog != tc.wantLog {
t.Errorf("Parse: log = %s wantLog %s", gotLog, tc.wantLog)