File tree Expand file tree Collapse file tree 5 files changed +31
-5
lines changed
examples/custom-strings/src Expand file tree Collapse file tree 5 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ help_flag_text: Show this helpful help
99version_flag_text : Show version number
1010
1111# Error messages
12- flag_requires_an_argument : " Hey! the flag %{long } requires an argument: %{usage}"
12+ flag_requires_an_argument : " Hey! the flag %{name } requires an argument: %{usage}"
1313missing_required_argument : " Boom! a required argument is missing: %{arg}\\ nusage: %{usage}"
1414missing_required_flag : " Yo! you forgot a flag: %{usage}"
1515
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ def aliases
1111 end
1212 end
1313
14+ def name
15+ long || short
16+ end
17+
1418 def usage_string ( extended : false )
1519 result = [ aliases . join ( ", " ) ]
1620 result << arg . upcase if arg
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ help_flag_text: Show this help
2121version_flag_text : Show version number
2222
2323# Error messages
24- flag_requires_an_argument : " %{long } requires an argument: %{usage}"
24+ flag_requires_an_argument : " %{name } requires an argument: %{usage}"
2525invalid_argument : " invalid argument: %s"
2626invalid_flag : " invalid option: %s"
2727missing_required_argument : " missing required argument: %{arg}\\ nusage: %{usage}"
Original file line number Diff line number Diff line change 22<%= aliases.join " | " %> )
33 <%- if arg -%>
44 if [[ $2 && $2 != -* ]]; then
5- args[<%= long %> ]="$2"
5+ args[<%= name %> ]="$2"
66 shift
77 shift
88 else
9- printf "%s\n" "<%= strings[:flag_requires_an_argument] % { long: long , usage: usage_string } %> "
9+ printf "%s\n" "<%= strings[:flag_requires_an_argument] % { name: name , usage: usage_string } %> "
1010 exit 1
1111 fi
1212 <%- else -%>
13- args[<%= long %> ]=1
13+ args[<%= name %> ]=1
1414 shift
1515 <%- end -%>
1616 ;;
Original file line number Diff line number Diff line change 2626 end
2727 end
2828
29+ describe '#name' do
30+ context "with both short and long options" do
31+ it "returns the long option" do
32+ expect ( subject . name ) . to eq "--help"
33+ end
34+ end
35+
36+ context "with long option only" do
37+ let ( :options ) { { "long" => "-l" } }
38+ it "returns the long option" do
39+ expect ( subject . name ) . to eq "-l"
40+ end
41+ end
42+
43+ context "with short option only" do
44+ let ( :options ) { { "short" => "-s" } }
45+ it "returns the short option" do
46+ expect ( subject . name ) . to eq "-s"
47+ end
48+ end
49+ end
50+
2951 describe '#usage_string' do
3052 it "returns a string suitable to be used as a usage pattern" do
3153 expect ( subject . usage_string ) . to eq "--help, -h"
You can’t perform that action at this time.
0 commit comments