@@ -1016,6 +1016,31 @@ Commands:
10161016 assert .Equal (t , expectedHelp [1 :], help .String ())
10171017}
10181018
1019+ func TestHelpSkipsSubcommandHelpDash (t * testing.T ) {
1020+ expectedHelp := `
1021+ Usage: example <command> [<args>]
1022+
1023+ Options:
1024+ --help, -h display this help and exit
1025+
1026+ Commands:
1027+ remove, rm, r remove something from somewhere
1028+ halt, stop stop now
1029+ `
1030+
1031+ var args struct {
1032+ Remove * struct {} `arg:"subcommand:remove|rm|r" help:"remove something from somewhere"`
1033+ Simple * struct {} `arg:"subcommand,hidden" help:"simple hidden subcommand"`
1034+ Stop * struct {} `arg:"subcommand:halt|stop" help:"stop now"`
1035+ }
1036+ p , err := NewParser (Config {Program : "example" }, & args )
1037+ require .NoError (t , err )
1038+
1039+ var help bytes.Buffer
1040+ p .WriteHelp (& help )
1041+ assert .Equal (t , expectedHelp [1 :], help .String ())
1042+ }
1043+
10191044func TestHelpShowsPositionalWithDefault (t * testing.T ) {
10201045 expectedHelp := `
10211046Usage: example [FOO]
@@ -1039,6 +1064,30 @@ Options:
10391064 assert .Equal (t , expectedHelp [1 :], help .String ())
10401065}
10411066
1067+ func TestHelpShowsPositionalWithDefaultSkipHidden (t * testing.T ) {
1068+ expectedHelp := `
1069+ Usage: example [FOO]
1070+
1071+ Positional arguments:
1072+ FOO this is a positional with a default [default: bar]
1073+
1074+ Options:
1075+ --help, -h display this help and exit
1076+ `
1077+
1078+ var args struct {
1079+ Foo string `arg:"positional" default:"bar" help:"this is a positional with a default"`
1080+ Bar string `arg:"positional,hidden" default:"baz" help:"this is a hidden positional with a default"`
1081+ }
1082+
1083+ p , err := NewParser (Config {Program : "example" }, & args )
1084+ require .NoError (t , err )
1085+
1086+ var help bytes.Buffer
1087+ p .WriteHelp (& help )
1088+ assert .Equal (t , expectedHelp [1 :], help .String ())
1089+ }
1090+
10421091func TestHelpShowsPositionalWithEnv (t * testing.T ) {
10431092 expectedHelp := `
10441093Usage: example [FOO]
0 commit comments