Skip to content

Commit

Permalink
Merge pull request #531 from DannyBen/fix/examples-on-error
Browse files Browse the repository at this point in the history
Fix `show_examples_on_error` when no examples
  • Loading branch information
DannyBen authored Jul 5, 2024
2 parents 58d7f20 + 60f03d0 commit 6f4304a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bashly/views/command/examples_on_error.gtx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions spec/approvals/fixtures/examples-on-error-without-examples
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cli
src/*.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
show_examples_on_error: true
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6f4304a

Please sign in to comment.