Skip to content

Commit f6c4797

Browse files
committed
fix shellcheck
1 parent e63c49a commit f6c4797

File tree

3 files changed

+63
-56
lines changed

3 files changed

+63
-56
lines changed

examples/repeatable-arg/README.md

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Repeatable Example
1+
# Repeatable Argument Example
22

3-
Demonstrates the use of repeatable flags that allow users to run commands such
4-
as `download -d one -d "two three" -vvv`.
3+
Demonstrates the use of repeatable arguments that allow users to run commands
4+
such `convert *.png` or `convert 1.png 2.png 3.png`.
55

66
This example was generated with:
77

88
```bash
9-
$ bashly init --minimal
9+
$ bashly init
1010
# ... now edit src/bashly.yml to match the example ...
1111
# ... now edit src/root_command.sh to match the example ...
1212
$ bashly generate
@@ -19,102 +19,108 @@ $ bashly generate
1919
## `bashly.yml`
2020

2121
```yaml
22-
name: download
23-
help: Sample application to demonstrate the use of repeatable flags
22+
name: upcase
23+
help: Sample application to demonstrate the use of repeatable arguments
2424
version: 0.1.0
2525

26-
flags:
27-
- long: --data
28-
short: -d
29-
arg: data
30-
help: Provide data values
26+
args:
27+
- name: file
28+
help: One or more files to process
3129
required: true
3230

33-
# Setting this to true on a flag with an argument means the user can type it
34-
# multiple times, like --data a --data b.
31+
# Setting repeatable to true means that the user can provide multiple arguments
32+
# for it.
3533
# 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]})"`
37-
repeatable: true
38-
39-
- long: --verbose
40-
short: -v
41-
help: Set verbosity level
42-
43-
# Setting this to true on a regular flag means the user can type it multiple
44-
# times, in the form of -vvv or -v -v -v.
45-
# The argument's value will hold the number of times it was entered.
34+
# needs to be converted to an array with `eval "data=(${args[file]})"`
4635
repeatable: true
4736

4837
examples:
49-
- download -d one -d "two three" -vvv
38+
- upcase README.md LICENSE
39+
- upcase *.md
5040
```
5141
5242
## `src/root_command.sh`
5343

5444
```bash
5545
# Convert the space delimited string to an array
56-
eval "data=(${args[--data]})"
57-
58-
echo "Data elements:"
59-
for i in "${data[@]}"; do
60-
echo "$i"
46+
files=''
47+
eval "files=(${args[file]})"
48+
49+
echo
50+
echo "files:"
51+
for i in "${files[@]}"; do
52+
echo " path: $i:"
53+
content="$(cat "$i")"
54+
echo " content: ${content}"
55+
echo " upcase: ${content^^}"
6156
done
6257
63-
# The --verbose arg will contain the number of times it was used by the user
64-
verbose=${args[--verbose]}
65-
echo ""
66-
echo "Verbosity level: $verbose"
67-
echo ""
68-
58+
echo
6959
inspect_args
7060
7161
```
7262

7363

7464
## Generated script output
7565

76-
### `$ ./download -h`
66+
### `$ ./upcase -h`
7767

7868
```shell
79-
download - Sample application to demonstrate the use of repeatable flags
69+
upcase - Sample application to demonstrate the use of repeatable arguments
8070
8171
Usage:
82-
download [options]
83-
download --help | -h
84-
download --version
72+
upcase FILE...
73+
upcase --help | -h
74+
upcase --version | -v
8575
8676
Options:
8777
--help, -h
8878
Show this help
8979
90-
--version
80+
--version, -v
9181
Show version number
9282
93-
--data, -d DATA (required) (repeatable)
94-
Provide data values
95-
96-
--verbose, -v (repeatable)
97-
Set verbosity level
83+
Arguments:
84+
FILE...
85+
One or more files to process
9886
9987
Examples:
100-
download -d one -d "two three" -vvv
88+
upcase README.md LICENSE
89+
upcase *.md
90+
10191
10292
93+
```
94+
95+
### `$ ./upcase file1`
96+
97+
```shell
98+
99+
files:
100+
path: file1:
101+
content: content of file1
102+
upcase: CONTENT OF FILE1
103+
104+
args:
105+
- ${args[file]} = "file1"
106+
103107
104108
```
105109

106-
### `$ ./download -d one -d "two three" -vvv`
110+
### `$ ./upcase file*`
107111

108112
```shell
109-
Data elements:
110-
one
111-
two three
112113
113-
Verbosity level: 3
114+
files:
115+
path: file1:
116+
content: content of file1
117+
upcase: CONTENT OF FILE1
118+
path: file2:
119+
content: content of file2
120+
upcase: CONTENT OF FILE2
114121
115122
args:
116-
- ${args[--data]} = "one" "two three"
117-
- ${args[--verbose]} = 3
123+
- ${args[file]} = "file1" "file2"
118124
119125
120126
```

examples/repeatable-arg/src/root_command.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Convert the space delimited string to an array
2+
files=''
23
eval "files=(${args[file]})"
34

45
echo

examples/repeatable-flag/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Repeatable Example
1+
# Repeatable Flag Example
22

33
Demonstrates the use of repeatable flags that allow users to run commands such
44
as `download -d one -d "two three" -vvv`.
@@ -46,7 +46,7 @@ flags:
4646
repeatable: true
4747

4848
examples:
49-
- download -d one -d "two three" -vvv
49+
- download -d one -d "two three" -vvv
5050
```
5151
5252
## `src/root_command.sh`

0 commit comments

Comments
 (0)