Skip to content

Commit 203c588

Browse files
committed
update examples for repeatable default arrays
1 parent c0c271e commit 203c588

File tree

11 files changed

+104
-20
lines changed

11 files changed

+104
-20
lines changed

examples/repeatable-arg/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ version: 0.1.0
2626
args:
2727
- name: file
2828
help: One or more files to process
29-
required: true
3029

3130
# Setting repeatable to true means that the user can provide multiple arguments
3231
# for it.
3332
# The argument will be received as a quoted and space-delimited string which
34-
# needs to be converted to an array with `eval "data=(${args[file]})"`
33+
# needs to be converted to an array with `eval "data=(${args[file]})"`.
3534
repeatable: true
3635

37-
# Setting unique to true will ignore non-unique repeating values
36+
# Setting unique to true will ignore non-unique repeating values.
3837
unique: true
3938

39+
# Setting default value(s) for a repeatable argument should be done in an
40+
# array form.
41+
default:
42+
- file1
43+
- file2
44+
4045
examples:
4146
- upcase README.md LICENSE
4247
- upcase *.md
@@ -47,7 +52,7 @@ examples:
4752
````bash
4853
# Convert the space delimited string to an array
4954
files=''
50-
eval "files=(${args[file]})"
55+
eval "files=(${args[file]:-})"
5156

5257
echo
5358
echo "files:"
@@ -72,7 +77,7 @@ inspect_args
7277
upcase - Sample application to demonstrate the use of repeatable arguments
7378

7479
Usage:
75-
upcase FILE...
80+
upcase [FILE...]
7681
upcase --help | -h
7782
upcase --version | -v
7883

@@ -86,13 +91,32 @@ Options:
8691
Arguments:
8792
FILE...
8893
One or more files to process
94+
Default: file1, file2
8995

9096
Examples:
9197
upcase README.md LICENSE
9298
upcase *.md
9399

94100

95101

102+
````
103+
104+
### `$ ./upcase`
105+
106+
````shell
107+
108+
files:
109+
path: file1:
110+
content: content of file1
111+
upcase: CONTENT OF FILE1
112+
path: file2:
113+
content: content of file2
114+
upcase: CONTENT OF FILE2
115+
116+
args:
117+
- ${args[file]} = file1 file2
118+
119+
96120
````
97121

98122
### `$ ./upcase file1`

examples/repeatable-arg/src/bashly.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ version: 0.1.0
55
args:
66
- name: file
77
help: One or more files to process
8-
required: true
98

109
# Setting repeatable to true means that the user can provide multiple arguments
1110
# for it.
1211
# The argument will be received as a quoted and space-delimited string which
13-
# needs to be converted to an array with `eval "data=(${args[file]})"`
12+
# needs to be converted to an array with `eval "data=(${args[file]})"`.
1413
repeatable: true
1514

16-
# Setting unique to true will ignore non-unique repeating values
15+
# Setting unique to true will ignore non-unique repeating values.
1716
unique: true
1817

18+
# Setting default value(s) for a repeatable argument should be done in an
19+
# array form.
20+
default:
21+
- file1
22+
- file2
23+
1924
examples:
2025
- upcase README.md LICENSE
2126
- upcase *.md

examples/repeatable-arg/src/root_command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Convert the space delimited string to an array
22
files=''
3-
eval "files=(${args[file]})"
3+
eval "files=(${args[file]:-})"
44

55
echo
66
echo "files:"

examples/repeatable-arg/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ bashly generate
77
### Try Me ###
88

99
./upcase -h
10+
./upcase
1011
./upcase file1
1112
./upcase file*
1213
./upcase file1 file2 file1

examples/repeatable-flag/README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ flags:
2828
short: -d
2929
arg: data
3030
help: Provide data values
31-
required: true
3231

3332
# Setting this to true on a flag with an argument means the user can type it
3433
# multiple times, like --data a --data b.
3534
# The argument will be received as a quoted and space-delimited string which
36-
# needs to be converted to an array with `eval "data=(${args[--data]})"`
35+
# needs to be converted to an array with `eval "data=(${args[--data]})"`.
3736
repeatable: true
3837

3938
- long: --path
@@ -42,9 +41,15 @@ flags:
4241
help: Specify one or more paths
4342
repeatable: true
4443

45-
# Setting this to true will ignore repeating arguments that are not unique
44+
# Setting this to true will ignore repeating arguments that are not unique.
4645
unique: true
4746

47+
# Setting default value(s) for a repeatable flag argument should be done in
48+
# an array form.
49+
default:
50+
- file one
51+
- file-two
52+
4853
- long: --verbose
4954
short: -v
5055
help: Set verbosity level
@@ -63,7 +68,7 @@ examples:
6368

6469
````bash
6570
# Convert the space delimited string to an array
66-
eval "data=(${args[--data]})"
71+
eval "data=(${args[--data]:-})"
6772

6873
echo "Data elements:"
6974
for i in "${data[@]}"; do
@@ -94,11 +99,12 @@ Usage:
9499
download --version
95100

96101
Options:
97-
--data, -d DATA (required) (repeatable)
102+
--data, -d DATA (repeatable)
98103
Provide data values
99104

100105
--path, -p LOCATION (repeatable)
101106
Specify one or more paths
107+
Default: file one, file-two
102108

103109
--verbose, -v (repeatable)
104110
Set verbosity level
@@ -115,6 +121,19 @@ Examples:
115121

116122

117123

124+
````
125+
126+
### `$ ./download`
127+
128+
````shell
129+
Data elements:
130+
131+
Verbosity level: 1
132+
133+
args:
134+
- ${args[--path]} = file\ one file-two
135+
136+
118137
````
119138

120139
### `$ ./download -d one -d "two three" -vvv`
@@ -128,6 +147,7 @@ Verbosity level: 3
128147

129148
args:
130149
- ${args[--data]} = "one" "two three"
150+
- ${args[--path]} = file\ one file-two
131151
- ${args[--verbose]} = 3
132152

133153

examples/repeatable-flag/src/bashly.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ flags:
77
short: -d
88
arg: data
99
help: Provide data values
10-
required: true
1110

1211
# Setting this to true on a flag with an argument means the user can type it
1312
# multiple times, like --data a --data b.
1413
# The argument will be received as a quoted and space-delimited string which
15-
# needs to be converted to an array with `eval "data=(${args[--data]})"`
14+
# needs to be converted to an array with `eval "data=(${args[--data]})"`.
1615
repeatable: true
1716

1817
- long: --path
@@ -21,9 +20,15 @@ flags:
2120
help: Specify one or more paths
2221
repeatable: true
2322

24-
# Setting this to true will ignore repeating arguments that are not unique
23+
# Setting this to true will ignore repeating arguments that are not unique.
2524
unique: true
2625

26+
# Setting default value(s) for a repeatable flag argument should be done in
27+
# an array form.
28+
default:
29+
- file one
30+
- file-two
31+
2732
- long: --verbose
2833
short: -v
2934
help: Set verbosity level

examples/repeatable-flag/src/root_command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Convert the space delimited string to an array
2-
eval "data=(${args[--data]})"
2+
eval "data=(${args[--data]:-})"
33

44
echo "Data elements:"
55
for i in "${data[@]}"; do

examples/repeatable-flag/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ bashly generate
77
### Try Me ###
88

99
./download -h
10+
./download
1011
./download -d one -d "two three" -vvv
1112
./download -d one --path /bin --path /usr/lib --path /bin

spec/approvals/examples/repeatable-arg

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ run ./upcase --help to test your bash script
77
upcase - Sample application to demonstrate the use of repeatable arguments
88

99
Usage:
10-
upcase FILE...
10+
upcase [FILE...]
1111
upcase --help | -h
1212
upcase --version | -v
1313

@@ -21,11 +21,24 @@ Options:
2121
Arguments:
2222
FILE...
2323
One or more files to process
24+
Default: file1, file2
2425

2526
Examples:
2627
upcase README.md LICENSE
2728
upcase *.md
2829

30+
+ ./upcase
31+
32+
files:
33+
path: file1:
34+
content: content of file1
35+
upcase: CONTENT OF FILE1
36+
path: file2:
37+
content: content of file2
38+
upcase: CONTENT OF FILE2
39+
40+
args:
41+
- ${args[file]} = file1 file2
2942
+ ./upcase file1
3043

3144
files:

spec/approvals/examples/repeatable-flag

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ Usage:
1212
download --version
1313

1414
Options:
15-
--data, -d DATA (required) (repeatable)
15+
--data, -d DATA (repeatable)
1616
Provide data values
1717

1818
--path, -p LOCATION (repeatable)
1919
Specify one or more paths
20+
Default: file one, file-two
2021

2122
--verbose, -v (repeatable)
2223
Set verbosity level
@@ -31,6 +32,13 @@ Examples:
3132
download -d one -d "two three" -vvv
3233
download -d one -p /usr/bin -p /tmp
3334

35+
+ ./download
36+
Data elements:
37+
38+
Verbosity level: 1
39+
40+
args:
41+
- ${args[--path]} = file\ one file-two
3442
+ ./download -d one -d 'two three' -vvv
3543
Data elements:
3644
one
@@ -40,6 +48,7 @@ Verbosity level: 3
4048

4149
args:
4250
- ${args[--data]} = "one" "two three"
51+
- ${args[--path]} = file\ one file-two
4352
- ${args[--verbose]} = 3
4453
+ ./download -d one --path /bin --path /usr/lib --path /bin
4554
Data elements:

0 commit comments

Comments
 (0)