diff --git a/lib/bashly/views/command/examples_on_error.gtx b/lib/bashly/views/command/examples_on_error.gtx index d9a0e80a..66999f50 100644 --- a/lib/bashly/views/command/examples_on_error.gtx +++ b/lib/bashly/views/command/examples_on_error.gtx @@ -1,4 +1,4 @@ -if Settings.show_examples_on_error && examples.any? +if Settings.show_examples_on_error && examples = view_marker > printf "{{ strings[:examples_caption_on_error] }}\n" >&2 diff --git a/spec/approvals/fixtures/examples-on-error-without-examples b/spec/approvals/fixtures/examples-on-error-without-examples new file mode 100644 index 00000000..fa6666a8 --- /dev/null +++ b/spec/approvals/fixtures/examples-on-error-without-examples @@ -0,0 +1,17 @@ +creating user files in src +created src/download_command.sh +created src/upload_command.sh +created ./cli +run ./cli --help to test your bash script ++ ./cli download +missing required argument: SOURCE +usage: cli download SOURCE ++ ./cli upload +missing required argument: SOURCE +usage: cli upload SOURCE +examples: + Upload a file + $ cli upload profile.png -u admin -p s3cr3t + + Upload a file (you will be prompted to provide a password) + $ cli upload profile.png --user admin diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/.gitignore b/spec/fixtures/workspaces/examples-on-error-without-examples/.gitignore new file mode 100644 index 00000000..235a70c8 --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/.gitignore @@ -0,0 +1,2 @@ +cli +src/*.sh diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/README.md b/spec/fixtures/workspaces/examples-on-error-without-examples/README.md new file mode 100644 index 00000000..511c360d --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/README.md @@ -0,0 +1,4 @@ +This fixture tests that generation does not fail when there are no examples, +and `show_examples_on_error` is set. + +Reference issue: https://github.com/DannyBen/bashly/pull/530#issuecomment-2210714825 diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/settings.yml b/spec/fixtures/workspaces/examples-on-error-without-examples/settings.yml new file mode 100644 index 00000000..0ed2f55b --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/settings.yml @@ -0,0 +1 @@ +show_examples_on_error: true diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/src/bashly.yml b/spec/fixtures/workspaces/examples-on-error-without-examples/src/bashly.yml new file mode 100644 index 00000000..f0b3cea1 --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/src/bashly.yml @@ -0,0 +1,27 @@ +name: cli +version: 0.1.0 + +commands: +- name: download + help: Download a file + + args: + - name: source + required: true + help: URL to download from + +- name: upload + help: Upload a file + args: + - name: source + required: true + help: File to upload + + examples: |- + Upload a file + $ cli upload profile.png -u admin -p s3cr3t + + Upload a file (you will be prompted to provide a password) + $ cli upload profile.png --user admin + + \ No newline at end of file diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/test.sh b/spec/fixtures/workspaces/examples-on-error-without-examples/test.sh new file mode 100644 index 00000000..8f6d12c5 --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +rm -f ./src/*.sh +rm -f ./cli + +bundle exec bashly generate + +set -x + +./cli download +./cli upload