diff --git a/examples/catch-all-stdin/README.md b/examples/catch-all-stdin/README.md index 6966fdc1..860b7ddc 100644 --- a/examples/catch-all-stdin/README.md +++ b/examples/catch-all-stdin/README.md @@ -11,6 +11,8 @@ $ bashly init $ bashly generate ``` + + ----- ## `bashly.yml` @@ -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 diff --git a/examples/catch-all-stdin/src/root_command.sh b/examples/catch-all-stdin/src/root_command.sh index 24b58e96..c15f1724 100644 --- a/examples/catch-all-stdin/src/root_command.sh +++ b/examples/catch-all-stdin/src/root_command.sh @@ -16,5 +16,3 @@ echo echo "collected file contents:" echo "$content" echo - - diff --git a/examples/catch-all-stdin/test.sh b/examples/catch-all-stdin/test.sh index adcbe450..7dcf381d 100644 --- a/examples/catch-all-stdin/test.sh +++ b/examples/catch-all-stdin/test.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -x - bashly generate ### Try Me ### diff --git a/spec/approvals/examples/catch-all-stdin b/spec/approvals/examples/catch-all-stdin index 0c98b0bc..db31c4dd 100644 --- a/spec/approvals/examples/catch-all-stdin +++ b/spec/approvals/examples/catch-all-stdin @@ -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: @@ -34,7 +32,6 @@ Examples: cat file1 | cli --format csv cat file* | cli - --format csv -+ ./cli file1 file2 --format csv args: - ${args[--format]} = csv @@ -48,7 +45,6 @@ file1 content file2 content -+ ./cli -f=csv file1 file2 args: - ${args[--format]} = csv @@ -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