From cc4ad5ef981d715ecf2c06b24f8c0e6151298362 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 5 Jul 2024 12:17:01 +0000 Subject: [PATCH 1/2] fix `show_examples_on_error` when no examples --- .../views/command/examples_on_error.gtx | 2 +- .../examples-on-error-without-examples | 17 ++++++++++++ .../.gitignore | 2 ++ .../README.md | 4 +++ .../settings.yml | 1 + .../src/bashly.yml | 27 +++++++++++++++++++ .../test.sh | 11 ++++++++ 7 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 spec/approvals/fixtures/examples-on-error-without-examples create mode 100644 spec/fixtures/workspaces/examples-on-error-without-examples/.gitignore create mode 100644 spec/fixtures/workspaces/examples-on-error-without-examples/README.md create mode 100644 spec/fixtures/workspaces/examples-on-error-without-examples/settings.yml create mode 100644 spec/fixtures/workspaces/examples-on-error-without-examples/src/bashly.yml create mode 100644 spec/fixtures/workspaces/examples-on-error-without-examples/test.sh 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..b7d0b2f4 --- /dev/null +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/README.md @@ -0,0 +1,4 @@ +This fixture tests that there is 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 From 60f03d0d2575c8ba66005df032a542effaaa1fac Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 5 Jul 2024 12:19:54 +0000 Subject: [PATCH 2/2] fix fixture readme --- .../workspaces/examples-on-error-without-examples/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/fixtures/workspaces/examples-on-error-without-examples/README.md b/spec/fixtures/workspaces/examples-on-error-without-examples/README.md index b7d0b2f4..511c360d 100644 --- a/spec/fixtures/workspaces/examples-on-error-without-examples/README.md +++ b/spec/fixtures/workspaces/examples-on-error-without-examples/README.md @@ -1,4 +1,4 @@ -This fixture tests that there is generation does not fail when there are no -examples, and `show_examples_on_error` is set +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