File tree Expand file tree Collapse file tree 9 files changed +35
-20
lines changed
Expand file tree Collapse file tree 9 files changed +35
-20
lines changed Original file line number Diff line number Diff line change @@ -101,9 +101,10 @@ def commands
101101 end
102102
103103 # Returns a flat array containing all the commands in this tree.
104- # This includes self + children + grandchildres + ...
105- def deep_commands
104+ # This can children + grandchildres (recursive), and may include self
105+ def deep_commands ( include_self : false )
106106 result = [ ]
107+ result << self if include_self
107108 commands . each do |command |
108109 result << command
109110 if command . commands . any?
@@ -217,6 +218,16 @@ def grouped_commands
217218 result
218219 end
219220
221+ # Returns true if this command, or any subcommand (deep) as any arg or
222+ # flag with arg that is defined as unique
223+ def has_unique_args_or_flags?
224+ deep_commands ( include_self : true ) . each do |command |
225+ return true if command . args . count ( &:unique ) . positive? ||
226+ command . flags . count ( &:unique ) . positive?
227+ end
228+ false
229+ end
230+
220231 # Returns a mode identifier
221232 def mode
222233 @mode ||= if global_flags? then :global_flags
Original file line number Diff line number Diff line change @@ -10,14 +10,13 @@ args.each do |arg|
1010 if arg.unique
1111 > elif [[ -z "${unique_lookup["{{ arg.name }}:$escaped"]:-}" ]]; then
1212 > args['{{ arg.name }}']="${args[{{ arg.name }}]} $escaped"
13- # TODO: This line should only be inserted if any uniques are used
1413 > unique_lookup["{{ arg.name }}:$escaped"]=1
1514 > shift
1615 > else
1716 > shift
1817 else
1918 > else
20- > args['{{ arg.name }}']="${args[{{ arg.name }}]} $escaped_value "
19+ > args['{{ arg.name }}']="${args[{{ arg.name }}]} $escaped "
2120 > shift
2221 end
2322
Original file line number Diff line number Diff line change 66> declare -a other_args=()
77> declare -a env_var_names=()
88> declare -a input=()
9- # TODO: This line should only be inserted if any uniques are used
10- > declare -A unique_lookup=()
9+ if has_unique_args_or_flags?
10+ > declare -A unique_lookup=()
11+ end
1112> normalize_input "$@"
1213> parse_requirements "${input[@]}"
1314if user_file_exist?('before')
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ if repeatable
1313 end
1414 > args['{{ name }}']="${args['{{ name }}']} $escaped"
1515 > fi
16- # TODO: This line should only be inserted if any uniques are used
17- > unique_lookup["{{ name }}:${escaped}"]=1
16+ if unique
17+ > unique_lookup["{{ name }}:${escaped}"]=1
18+ end
1819
1920else
2021 > args['{{ name }}']="$2"
Original file line number Diff line number Diff line change 4747 upcase: CONTENT OF FILE1
4848
4949args:
50- - ${args[file]} = " file1"
50+ - ${args[file]} = file1
5151+ ./upcase file1 file2
5252
5353files:
5959 upcase: CONTENT OF FILE2
6060
6161args:
62- - ${args[file]} = " file1" " file2"
62+ - ${args[file]} = file1 file2
6363+ ./upcase file1 file2 file1
6464
6565files:
6969 path: file2:
7070 content: content of file2
7171 upcase: CONTENT OF FILE2
72+ path: file1:
73+ content: content of file1
74+ upcase: CONTENT OF FILE1
7275
7376args:
74- - ${args[file]} = " file1" " file2"
77+ - ${args[file]} = file1 file2 file1
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ two three
4747Verbosity level: 3
4848
4949args:
50- - ${args[--data]} = " one" " two three"
50+ - ${args[--data]} = one two\ three
5151- ${args[--path]} = file\ one file-two
5252- ${args[--verbose]} = 3
5353+ ./download -d one --path /bin --path /usr/lib --path /bin
5757Verbosity level: 1
5858
5959args:
60- - ${args[--data]} = " one"
61- - ${args[--path]} = " /bin" " /usr/lib"
60+ - ${args[--data]} = one
61+ - ${args[--path]} = /bin /usr/lib
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ args: none
1111# this file is located in 'src/root_command.sh'
1212# you can edit it freely and regenerate (it will not be overwritten)
1313args:
14- - ${args[number]} = "1"
14+ - ${args[number]} = 1
1515+ ./cli 1.1
1616validation error in NUMBER:
1717must be an integer
@@ -22,7 +22,7 @@ must be an integer
2222# this file is located in 'src/root_command.sh'
2323# you can edit it freely and regenerate (it will not be overwritten)
2424args:
25- - ${args[number]} = "1" "2"
25+ - ${args[number]} = 1 2
2626+ ./cli 1.1 2
2727validation error in NUMBER:
2828must be an integer
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ args: none
1111# this file is located in 'src/root_command.sh'
1212# you can edit it freely and regenerate (it will not be overwritten)
1313args:
14- - ${args[--number]} = "1"
14+ - ${args[--number]} = 1
1515+ ./cli --number 1.1
1616validation error in --number, -n NUMBER:
1717must be an integer
@@ -22,7 +22,7 @@ must be an integer
2222# this file is located in 'src/root_command.sh'
2323# you can edit it freely and regenerate (it will not be overwritten)
2424args:
25- - ${args[--number]} = "1" "2"
25+ - ${args[--number]} = 1 2
2626+ ./cli --number 1.1 --number 2
2727validation error in --number, -n NUMBER:
2828must be an integer
Original file line number Diff line number Diff line change @@ -12,12 +12,12 @@ args:
1212# this file is located in 'src/root_command.sh'
1313# you can edit it freely and regenerate (it will not be overwritten)
1414args:
15- - ${args[--protocol]} = " ssh"
15+ - ${args[--protocol]} = ssh
1616+ ./download -p ssh -p ftp
1717# this file is located in 'src/root_command.sh'
1818# you can edit it freely and regenerate (it will not be overwritten)
1919args:
20- - ${args[--protocol]} = " ssh" " ftp"
20+ - ${args[--protocol]} = ssh ftp
2121+ ./download -p sftp -p https
2222--protocol must be one of: ssh, ftp, sftp
2323+ ./download -p http -p ftp
You can’t perform that action at this time.
0 commit comments