Skip to content

Commit 2ba6da3

Browse files
committed
update catch all stdin example
1 parent 5c5f447 commit 2ba6da3

File tree

3 files changed

+155
-5
lines changed

3 files changed

+155
-5
lines changed

examples/catch-all-stdin/README.md

+140
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,143 @@ $ bashly generate
1313

1414
-----
1515

16+
## `bashly.yml`
17+
18+
```yaml
19+
name: cli
20+
help: Sample application
21+
version: 0.1.0
22+
23+
catch_all:
24+
label: file
25+
help: Path to one or more files. Reads from stdin if empty or "-".
26+
27+
flags:
28+
- long: --format
29+
short: -f
30+
arg: format
31+
help: Specify file format
32+
default: json
33+
allowed: [csv, json]
34+
35+
examples:
36+
- cli file1 file2 --format csv
37+
- cli --format csv file1 file2
38+
- cat file1 | cli --format csv
39+
- cat file* | cli - --format csv
40+
```
41+
42+
43+
44+
## Generated script output
45+
46+
### `$ ./cli -h`
47+
48+
```shell
49+
cli - Sample application
50+
51+
Usage:
52+
cli [options] [FILE...]
53+
cli --help | -h
54+
cli --version | -v
55+
56+
Options:
57+
--help, -h
58+
Show this help
59+
60+
--version, -v
61+
Show version number
62+
63+
--format, -f FORMAT
64+
Specify file format
65+
Allowed: csv, json
66+
Default: json
67+
68+
Arguments:
69+
FILE...
70+
Path to one or more files. Reads from stdin if empty or "-".
71+
72+
Examples:
73+
cli file1 file2 --format csv
74+
cli --format csv file1 file2
75+
cat file1 | cli --format csv
76+
cat file* | cli - --format csv
77+
78+
79+
80+
```
81+
82+
### `$ ./cli file1 file2 --format csv`
83+
84+
```shell
85+
args:
86+
- ${args[--format]} = csv
87+
88+
other_args:
89+
- ${other_args[*]} = file1 file2
90+
- ${other_args[0]} = file1
91+
- ${other_args[1]} = file2
92+
93+
collected file contents:
94+
file1 content
95+
file2 content
96+
97+
98+
99+
100+
```
101+
102+
### `$ ./cli -f=csv file1 file2`
103+
104+
```shell
105+
args:
106+
- ${args[--format]} = csv
107+
108+
other_args:
109+
- ${other_args[*]} = file1 file2
110+
- ${other_args[0]} = file1
111+
- ${other_args[1]} = file2
112+
113+
collected file contents:
114+
file1 content
115+
file2 content
116+
117+
118+
119+
120+
```
121+
122+
### `$ cat file1 | ./cli --format csv`
123+
124+
```shell
125+
args:
126+
- ${args[--format]} = csv
127+
128+
collected file contents:
129+
file1 content
130+
131+
132+
133+
```
134+
135+
### `$ cat file* | ./cli -`
136+
137+
```shell
138+
args:
139+
- ${args[--format]} = json
140+
141+
other_args:
142+
- ${other_args[*]} = -
143+
- ${other_args[0]} = -
144+
145+
collected file contents:
146+
file1 content
147+
file2 content
148+
149+
150+
151+
152+
```
153+
154+
155+

examples/catch-all-stdin/src/root_command.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ if [[ -z "$content" ]]; then
1515
content="$(cat -)"
1616
fi
1717

18-
echo "Collected file contents:"
18+
echo
19+
echo "collected file contents:"
1920
echo "$content"
21+
echo
2022

2123

spec/approvals/examples/catch-all-stdin

+12-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ other_args:
4242
- ${other_args[*]} = file1 file2
4343
- ${other_args[0]} = file1
4444
- ${other_args[1]} = file2
45-
Collected file contents:
45+
46+
collected file contents:
4647
file1 content
4748
file2 content
4849

50+
4951
+ ./cli -f=csv file1 file2
5052
args:
5153
- ${args[--format]} = csv
@@ -54,16 +56,20 @@ other_args:
5456
- ${other_args[*]} = file1 file2
5557
- ${other_args[0]} = file1
5658
- ${other_args[1]} = file2
57-
Collected file contents:
59+
60+
collected file contents:
5861
file1 content
5962
file2 content
6063

64+
6165
+ cat file1
6266
+ ./cli --format csv
6367
args:
6468
- ${args[--format]} = csv
65-
Collected file contents:
69+
70+
collected file contents:
6671
file1 content
72+
6773
+ ./cli -
6874
+ cat file1 file2
6975
args:
@@ -72,7 +78,9 @@ args:
7278
other_args:
7379
- ${other_args[*]} = -
7480
- ${other_args[0]} = -
75-
Collected file contents:
81+
82+
collected file contents:
7683
file1 content
7784
file2 content
7885

86+

0 commit comments

Comments
 (0)