Skip to content

Commit 0115c89

Browse files
authored
Merge pull request #511 from DannyBen/fix/double-dash-passthru
Fix input normalization to ignore anything after the double dash (--) operator
2 parents 0696ca4 + df22071 commit 0115c89

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

examples/catch-all-advanced/test.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ bashly generate
1212
./cli download -h
1313
./cli download source
1414
./cli download source target
15-
./cli download source target and --additional stuff
15+
./cli download source target --force
16+
17+
# when passing arbitrary arguments that start with a hyphen...
18+
./cli download source target --force -abc --option=value
19+
20+
# ...use the double dash (--) operator to disable input normalization
21+
./cli download source target --force -- -abc --option=value
1622

1723
./cli upload -h
1824
./cli upload

lib/bashly/views/command/normalize_input.gtx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
= view_marker
22

33
> normalize_input() {
4-
> local arg flags
4+
> local arg flags passthru
5+
> passthru=false
56
>
67
> while [[ $# -gt 0 ]]; do
78
> arg="$1"
8-
> if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
9+
> if [[ $passthru == true ]]; then
10+
> input+=("$arg")
11+
> elif [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
912
> input+=("${BASH_REMATCH[1]}")
1013
> input+=("${BASH_REMATCH[2]}")
1114
> elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
@@ -20,6 +23,9 @@ if Settings.compact_short_flags
2023
> done
2124
end
2225

26+
> elif [[ "$arg" == "--" ]]; then
27+
> passthru=true
28+
> input+=("$arg")
2329
> else
2430
> input+=("$arg")
2531
> fi

spec/approvals/examples/catch-all-advanced

+29-5
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,43 @@ args:
5959
args:
6060
- ${args[source]} = source
6161
- ${args[target]} = target
62-
+ ./cli download source target and --additional stuff
62+
+ ./cli download source target --force
6363
# this file is located in 'src/download_command.sh'
6464
# code for 'cli download' goes here
6565
# you can edit it freely and regenerate (it will not be overwritten)
6666
args:
67+
- ${args[--force]} = 1
68+
- ${args[source]} = source
69+
- ${args[target]} = target
70+
+ ./cli download source target --force -abc --option=value
71+
# this file is located in 'src/download_command.sh'
72+
# code for 'cli download' goes here
73+
# you can edit it freely and regenerate (it will not be overwritten)
74+
args:
75+
- ${args[--force]} = 1
76+
- ${args[source]} = source
77+
- ${args[target]} = target
78+
79+
other_args:
80+
- ${other_args[*]} = -a -b -c --option value
81+
- ${other_args[0]} = -a
82+
- ${other_args[1]} = -b
83+
- ${other_args[2]} = -c
84+
- ${other_args[3]} = --option
85+
- ${other_args[4]} = value
86+
+ ./cli download source target --force -- -abc --option=value
87+
# this file is located in 'src/download_command.sh'
88+
# code for 'cli download' goes here
89+
# you can edit it freely and regenerate (it will not be overwritten)
90+
args:
91+
- ${args[--force]} = 1
6792
- ${args[source]} = source
6893
- ${args[target]} = target
6994

7095
other_args:
71-
- ${other_args[*]} = and --additional stuff
72-
- ${other_args[0]} = and
73-
- ${other_args[1]} = --additional
74-
- ${other_args[2]} = stuff
96+
- ${other_args[*]} = -abc --option=value
97+
- ${other_args[0]} = -abc
98+
- ${other_args[1]} = --option=value
7599
+ ./cli upload -h
76100
cli upload - Upload a file
77101

0 commit comments

Comments
 (0)