Skip to content

Commit 011c648

Browse files
committed
example update
1 parent 2f54072 commit 011c648

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

examples/catch-all-stdin/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $ bashly init
1111
$ bashly generate
1212
```
1313

14+
<!-- include: src/root_command.sh -->
15+
1416
-----
1517

1618
## `bashly.yml`
@@ -39,6 +41,29 @@ examples:
3941
- cat file* | cli - --format csv
4042
```
4143
44+
## `src/root_command.sh`
45+
46+
```bash
47+
inspect_args
48+
49+
# Read contents of the provided file(s)
50+
content=""
51+
for file in "${other_args[@]}"; do
52+
content+="$(cat "$file")"
53+
content+=$'\n'
54+
done
55+
56+
# Read stdin if file(s) not provided as arguments
57+
if [[ -z "$content" ]]; then
58+
content="$(cat -)"
59+
fi
60+
61+
echo
62+
echo "collected file contents:"
63+
echo "$content"
64+
echo
65+
66+
```
4267

4368

4469
## Generated script output

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ echo
1616
echo "collected file contents:"
1717
echo "$content"
1818
echo
19-
20-

examples/catch-all-stdin/test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
set -x
4-
53
bashly generate
64

75
### Try Me ###

spec/approvals/examples/catch-all-stdin

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
+ bashly generate
21
creating user files in src
32
skipped src/initialize.sh (exists)
43
skipped src/root_command.sh (exists)
54
created ./cli
65
run ./cli --help to test your bash script
7-
+ ./cli -h
86
cli - Sample application
97

108
Usage:
@@ -34,7 +32,6 @@ Examples:
3432
cat file1 | cli --format csv
3533
cat file* | cli - --format csv
3634

37-
+ ./cli file1 file2 --format csv
3835
args:
3936
- ${args[--format]} = csv
4037

@@ -48,7 +45,6 @@ file1 content
4845
file2 content
4946

5047

51-
+ ./cli -f=csv file1 file2
5248
args:
5349
- ${args[--format]} = csv
5450

@@ -62,16 +58,12 @@ file1 content
6258
file2 content
6359

6460

65-
+ cat file1
66-
+ ./cli --format csv
6761
args:
6862
- ${args[--format]} = csv
6963

7064
collected file contents:
7165
file1 content
7266

73-
+ ./cli -
74-
+ cat file1 file2
7567
args:
7668
- ${args[--format]} = json
7769

0 commit comments

Comments
 (0)