File tree Expand file tree Collapse file tree 7 files changed +88
-36
lines changed
Expand file tree Collapse file tree 7 files changed +88
-36
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,12 @@ def parents
111111 options [ 'parents' ] || [ ]
112112 end
113113
114- # Returns trus if this is the root command (no parents)
114+ # Returns true if one of the args is repeatable
115+ def repeatable_arg_exist?
116+ args . select ( &:repeatable ) . any?
117+ end
118+
119+ # Returns true if this is the root command (no parents)
115120 def root_command?
116121 parents . empty?
117122 end
Original file line number Diff line number Diff line change 11<%= view_marker %>
2- % repeatable_arg = false
3- % if args.any?
4- % condition = "if"
5- % args.each do |arg|
6- <%= condition %> [[ -z ${args[<%= arg.name %> ]+x} ]]; then
7- <%= arg.render(:validations).indent 2 %>
8- % if arg.repeatable
9- % repeatable_arg = true
10- args[<%= arg.name %> ]="\"$1\""
11- shift
12- else
13- args[<%= arg.name %> ]="${args[<%= arg.name %> ]} \"$1\""
14- shift
15- % else
16- args[<%= arg.name %> ]=$1
17- shift
18- % end
19- % condition = "elif"
20- % end
21- % if !repeatable_arg
22- else
23- % end
242% if catch_all.enabled?
25- other_args+=("$1")
26- shift
27- % elsif !repeatable_arg
28- printf "<%= strings[:invalid_argument] %> \n" "$key"
29- exit 1
30- % end
31- fi
32- % elsif catch_all.enabled?
33- other_args+=("$1")
34- shift
35- % elsif !repeatable_arg
36- printf "<%= strings[:invalid_argument] %> \n" "$key"
37- exit 1
3+ <%= render(:parse_requirements_case_catch_all) %>
4+ % elsif repeatable_arg_exist?
5+ <%= render(:parse_requirements_case_repeatable) %>
6+ % else
7+ <%= render(:parse_requirements_case_simple) %>
388% end
Original file line number Diff line number Diff line change 1+ <%= view_marker %>
2+ % if args.any?
3+ % condition = "if"
4+ % args.each do |arg|
5+ <%= condition %> [[ -z ${args[<%= arg.name %> ]+x} ]]; then
6+ <%= arg.render(:validations).indent 2 %>
7+ args[<%= arg.name %> ]=$1
8+ shift
9+ % condition = "elif"
10+ % end
11+ else
12+ other_args+=("$1")
13+ shift
14+ fi
15+ % else
16+ other_args+=("$1")
17+ shift
18+ % end
Original file line number Diff line number Diff line change 1+ <%= view_marker %>
2+ % condition = "if"
3+ % args.each do |arg|
4+ <%= condition %> [[ -z ${args[<%= arg.name %> ]+x} ]]; then
5+ <%= arg.render(:validations).indent 2 %>
6+ % if arg.repeatable
7+ args[<%= arg.name %> ]="\"$1\""
8+ shift
9+ else
10+ args[<%= arg.name %> ]="${args[<%= arg.name %> ]} \"$1\""
11+ shift
12+ % else
13+ args[<%= arg.name %> ]=$1
14+ shift
15+ % end
16+ % condition = "elif"
17+ % end
18+ fi
Original file line number Diff line number Diff line change 1+ <%= view_marker %>
2+ % if args.any?
3+ % condition = "if"
4+ % args.each do |arg|
5+ <%= condition %> [[ -z ${args[<%= arg.name %> ]+x} ]]; then
6+ <%= arg.render(:validations).indent 2 %>
7+ args[<%= arg.name %> ]=$1
8+ shift
9+ % condition = "elif"
10+ % end
11+ else
12+ printf "<%= strings[:invalid_argument] %> \n" "$key"
13+ exit 1
14+ fi
15+ % else
16+ printf "<%= strings[:invalid_argument] %> \n" "$key"
17+ exit 1
18+ % end
Original file line number Diff line number Diff line change 242242 end
243243 end
244244
245+ describe '#repeatable_arg_exist?' do
246+ context "when the command does not have any repeatable flags" do
247+ it "returns false" do
248+ expect ( subject . repeatable_arg_exist? ) . to be false
249+ end
250+ end
251+
252+ context "when the command has at least one repeatable flag" do
253+ let ( :fixture ) { :repeatable_arg }
254+
255+ it "returns true" do
256+ expect ( subject . repeatable_arg_exist? ) . to be true
257+ end
258+ end
259+ end
260+
245261 describe '#root_command?' do
246262 context "when the command has no parents" do
247263 it "returns true" do
Original file line number Diff line number Diff line change 179179:filters_string :
180180 name : run
181181 filters : docker_running
182+
183+ :repeatable_arg :
184+ name : get
185+ args :
186+ - name : source
187+ - name : target
188+ repeatable : true
You can’t perform that action at this time.
0 commit comments