@@ -1015,3 +1015,72 @@ Commands:
1015
1015
p .WriteHelp (& help )
1016
1016
assert .Equal (t , expectedHelp [1 :], help .String ())
1017
1017
}
1018
+
1019
+ func TestHelpShowsPositionalWithDefault (t * testing.T ) {
1020
+ expectedHelp := `
1021
+ Usage: example [FOO]
1022
+
1023
+ Positional arguments:
1024
+ FOO this is a positional with a default [default: bar]
1025
+
1026
+ Options:
1027
+ --help, -h display this help and exit
1028
+ `
1029
+
1030
+ var args struct {
1031
+ Foo string `arg:"positional" default:"bar" help:"this is a positional with a default"`
1032
+ }
1033
+
1034
+ p , err := NewParser (Config {Program : "example" }, & args )
1035
+ require .NoError (t , err )
1036
+
1037
+ var help bytes.Buffer
1038
+ p .WriteHelp (& help )
1039
+ assert .Equal (t , expectedHelp [1 :], help .String ())
1040
+ }
1041
+
1042
+ func TestHelpShowsPositionalWithEnv (t * testing.T ) {
1043
+ expectedHelp := `
1044
+ Usage: example [FOO]
1045
+
1046
+ Positional arguments:
1047
+ FOO this is a positional with an env variable [env: FOO]
1048
+
1049
+ Options:
1050
+ --help, -h display this help and exit
1051
+ `
1052
+
1053
+ var args struct {
1054
+ Foo string `arg:"positional,env:FOO" help:"this is a positional with an env variable"`
1055
+ }
1056
+
1057
+ p , err := NewParser (Config {Program : "example" }, & args )
1058
+ require .NoError (t , err )
1059
+
1060
+ var help bytes.Buffer
1061
+ p .WriteHelp (& help )
1062
+ assert .Equal (t , expectedHelp [1 :], help .String ())
1063
+ }
1064
+
1065
+ func TestHelpShowsPositionalWithDefaultAndEnv (t * testing.T ) {
1066
+ expectedHelp := `
1067
+ Usage: example [FOO]
1068
+
1069
+ Positional arguments:
1070
+ FOO this is a positional with a default and an env variable [default: bar, env: FOO]
1071
+
1072
+ Options:
1073
+ --help, -h display this help and exit
1074
+ `
1075
+
1076
+ var args struct {
1077
+ Foo string `arg:"positional,env:FOO" default:"bar" help:"this is a positional with a default and an env variable"`
1078
+ }
1079
+
1080
+ p , err := NewParser (Config {Program : "example" }, & args )
1081
+ require .NoError (t , err )
1082
+
1083
+ var help bytes.Buffer
1084
+ p .WriteHelp (& help )
1085
+ assert .Equal (t , expectedHelp [1 :], help .String ())
1086
+ }
0 commit comments