Skip to content

Commit 5701dbd

Browse files
authored
Merge pull request #317 from DannyBen/add/double-dash-support
Add support for double dash as an argument parsing terminator
2 parents f659bfc + 6977c2d commit 5701dbd

File tree

7 files changed

+66
-8
lines changed

7 files changed

+66
-8
lines changed

edge/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ FROM dannyben/alpine-ruby
33
ENV PS1 "\n\n>> bashly \W \$ "
44
RUN apk add --no-cache git
55

6+
ARG branch=master
7+
68
WORKDIR /bashly
7-
RUN git clone --depth 1 https://github.com/DannyBen/bashly.git .
9+
RUN git clone --branch $branch --depth 1 https://github.com/DannyBen/bashly.git .
810
RUN gem build bashly.gemspec
911
RUN gem install bashly*.gem
1012

edge/op.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
build: docker build --no-cache -t dannyben/bashly:edge . && docker images |grep bashly
1+
build: docker build --build-arg=branch=${1:-master} --no-cache -t dannyben/bashly:edge . && docker images |grep bashly
22
push: docker push dannyben/bashly:edge

examples/catch-all/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ args:
2727
- name: message
2828
required: true
2929
help: Message
30+
31+
flags:
32+
- long: --debug
33+
short: -d
3034
```
3135
3236
@@ -37,7 +41,7 @@ args:
3741

3842
```shell
3943
missing required argument: MESSAGE
40-
usage: download MESSAGE [...]
44+
usage: download MESSAGE [OPTIONS] [...]
4145
4246
4347
```
@@ -48,7 +52,7 @@ usage: download MESSAGE [...]
4852
download - Catch All Example
4953
5054
Usage:
51-
download MESSAGE [...]
55+
download MESSAGE [OPTIONS] [...]
5256
download --help | -h
5357
download --version | -v
5458
@@ -59,6 +63,9 @@ Options:
5963
--version, -v
6064
Show version number
6165
66+
--debug, -d
67+
68+
6269
Arguments:
6370
MESSAGE
6471
Message
@@ -95,5 +102,25 @@ other_args:
95102
96103
```
97104

105+
### `$ ./download something --debug -- also pass --debug to catch_all`
106+
107+
```shell
108+
# this file is located in 'src/root_command.sh'
109+
# you can edit it freely and regenerate (it will not be overwritten)
110+
args:
111+
- ${args[--debug]} = 1
112+
- ${args[message]} = something
113+
114+
other_args:
115+
- ${other_args[*]} = also pass --debug to catch_all
116+
- ${other_args[0]} = also
117+
- ${other_args[1]} = pass
118+
- ${other_args[2]} = --debug
119+
- ${other_args[3]} = to
120+
- ${other_args[4]} = catch_all
121+
122+
123+
```
124+
98125

99126

examples/catch-all/src/bashly.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ args:
1010
required: true
1111
help: Message
1212

13+
flags:
14+
- long: --debug
15+
short: -d

examples/catch-all/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ bashly generate
1111
./download
1212
./download -h
1313
./download something
14-
./download something with --additional args
14+
./download something with --additional args
15+
./download something --debug -- also pass --debug to catch_all

lib/bashly/views/command/parse_requirements_while.gtx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ unless global_flags?
1111
end
1212

1313
>
14-
> -?*)
14+
if catch_all.enabled?
15+
> --)
16+
> shift
17+
> other_args+=("$@")
18+
> break
19+
> ;;
20+
>
21+
end
1522

23+
> -?*)
1624
if catch_all.enabled?
1725
> other_args+=("$1")
1826
> shift

spec/approvals/examples/catch-all

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ created ./download
66
run ./download --help to test your bash script
77
+ ./download
88
missing required argument: MESSAGE
9-
usage: download MESSAGE [...]
9+
usage: download MESSAGE [OPTIONS] [...]
1010
+ ./download -h
1111
download - Catch All Example
1212

1313
Usage:
14-
download MESSAGE [...]
14+
download MESSAGE [OPTIONS] [...]
1515
download --help | -h
1616
download --version | -v
1717

@@ -22,6 +22,9 @@ Options:
2222
--version, -v
2323
Show version number
2424

25+
--debug, -d
26+
27+
2528
Arguments:
2629
MESSAGE
2730
Message
@@ -42,3 +45,17 @@ other_args:
4245
- ${other_args[0]} = with
4346
- ${other_args[1]} = --additional
4447
- ${other_args[2]} = args
48+
+ ./download something --debug -- also pass --debug to catch_all
49+
# this file is located in 'src/root_command.sh'
50+
# you can edit it freely and regenerate (it will not be overwritten)
51+
args:
52+
- ${args[--debug]} = 1
53+
- ${args[message]} = something
54+
55+
other_args:
56+
- ${other_args[*]} = also pass --debug to catch_all
57+
- ${other_args[0]} = also
58+
- ${other_args[1]} = pass
59+
- ${other_args[2]} = --debug
60+
- ${other_args[3]} = to
61+
- ${other_args[4]} = catch_all

0 commit comments

Comments
 (0)