Skip to content

Commit

Permalink
example update
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Mar 31, 2022
1 parent 2f54072 commit 011c648
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
25 changes: 25 additions & 0 deletions examples/catch-all-stdin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $ bashly init
$ bashly generate
```

<!-- include: src/root_command.sh -->

-----

## `bashly.yml`
Expand Down Expand Up @@ -39,6 +41,29 @@ examples:
- cat file* | cli - --format csv
```
## `src/root_command.sh`

```bash
inspect_args
# Read contents of the provided file(s)
content=""
for file in "${other_args[@]}"; do
content+="$(cat "$file")"
content+=$'\n'
done
# Read stdin if file(s) not provided as arguments
if [[ -z "$content" ]]; then
content="$(cat -)"
fi
echo
echo "collected file contents:"
echo "$content"
echo
```


## Generated script output
Expand Down
2 changes: 0 additions & 2 deletions examples/catch-all-stdin/src/root_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ echo
echo "collected file contents:"
echo "$content"
echo


2 changes: 0 additions & 2 deletions examples/catch-all-stdin/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

set -x

bashly generate

### Try Me ###
Expand Down
8 changes: 0 additions & 8 deletions spec/approvals/examples/catch-all-stdin
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
+ bashly generate
creating user files in src
skipped src/initialize.sh (exists)
skipped src/root_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
+ ./cli -h
cli - Sample application

Usage:
Expand Down Expand Up @@ -34,7 +32,6 @@ Examples:
cat file1 | cli --format csv
cat file* | cli - --format csv

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

Expand All @@ -48,7 +45,6 @@ file1 content
file2 content


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

Expand All @@ -62,16 +58,12 @@ file1 content
file2 content


+ cat file1
+ ./cli --format csv
args:
- ${args[--format]} = csv

collected file contents:
file1 content

+ ./cli -
+ cat file1 file2
args:
- ${args[--format]} = json

Expand Down

0 comments on commit 011c648

Please sign in to comment.