-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from DannyBen/add/show-examples-on-error
Add `show_examples_on_error` setting
- Loading branch information
Showing
17 changed files
with
255 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Command Examples on Error Example | ||
|
||
Demonstrates how to show examples whenever the user does not provide all the | ||
required arguments. | ||
|
||
This example was generated with: | ||
|
||
```bash | ||
$ bashly init | ||
# ... now edit src/bashly.yml to match the example ... | ||
$ bashly add settings | ||
# ... now edit settings.yml to match the example ... | ||
$ bashly generate | ||
``` | ||
|
||
<!-- include: settings.yml --> | ||
|
||
----- | ||
|
||
## `bashly.yml` | ||
|
||
````yaml | ||
name: cli | ||
help: Sample application | ||
version: 0.1.0 | ||
|
||
commands: | ||
- name: download | ||
alias: d | ||
help: Download a file | ||
|
||
args: | ||
- name: source | ||
required: true | ||
help: URL to download from | ||
- name: target | ||
help: "Target filename (default: same as source)" | ||
|
||
flags: | ||
- long: --force | ||
short: -f | ||
help: Overwrite existing files | ||
|
||
# Examples can be provided either as an array, or as a string. | ||
# The array form is convenient when you just want to provide one-liner | ||
# examples. | ||
examples: | ||
- cli download example.com | ||
- cli download example.com ./output -f | ||
|
||
- name: upload | ||
alias: u | ||
help: Upload a file | ||
args: | ||
- name: source | ||
required: true | ||
help: File to upload | ||
|
||
flags: | ||
- long: --user | ||
short: -u | ||
arg: user | ||
help: Username to use for logging in | ||
required: true | ||
- long: --password | ||
short: -p | ||
arg: password | ||
help: Password to use for logging in | ||
|
||
# The string form examples is useful when you wish to have more control | ||
# over how the examples are displayed. Note the use of the '|-' marker | ||
# that tells YAML to use the string as is, including the newlines it contains. | ||
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 | ||
```` | ||
|
||
## `settings.yml` | ||
|
||
````yaml | ||
show_examples_on_error: true | ||
|
||
```` | ||
|
||
|
||
## Output | ||
|
||
### `$ ./cli download` | ||
|
||
````shell | ||
missing required argument: SOURCE | ||
usage: cli download SOURCE [TARGET] [OPTIONS] | ||
examples: | ||
cli download example.com | ||
cli download example.com ./output -f | ||
|
||
|
||
```` | ||
|
||
### `$ ./cli upload` | ||
|
||
````shell | ||
missing required argument: SOURCE | ||
usage: cli upload SOURCE [OPTIONS] | ||
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 | ||
|
||
|
||
```` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
show_examples_on_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: cli | ||
help: Sample application | ||
version: 0.1.0 | ||
|
||
commands: | ||
- name: download | ||
alias: d | ||
help: Download a file | ||
|
||
args: | ||
- name: source | ||
required: true | ||
help: URL to download from | ||
- name: target | ||
help: "Target filename (default: same as source)" | ||
|
||
flags: | ||
- long: --force | ||
short: -f | ||
help: Overwrite existing files | ||
|
||
# Examples can be provided either as an array, or as a string. | ||
# The array form is convenient when you just want to provide one-liner | ||
# examples. | ||
examples: | ||
- cli download example.com | ||
- cli download example.com ./output -f | ||
|
||
- name: upload | ||
alias: u | ||
help: Upload a file | ||
args: | ||
- name: source | ||
required: true | ||
help: File to upload | ||
|
||
flags: | ||
- long: --user | ||
short: -u | ||
arg: user | ||
help: Username to use for logging in | ||
required: true | ||
- long: --password | ||
short: -p | ||
arg: password | ||
help: Password to use for logging in | ||
|
||
# The string form examples is useful when you wish to have more control | ||
# over how the examples are displayed. Note the use of the '|-' marker | ||
# that tells YAML to use the string as is, including the newlines it contains. | ||
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
echo "# this file is located in 'src/download_command.sh'" | ||
echo "# code for 'cli download' goes here" | ||
echo "# you can edit it freely and regenerate (it will not be overwritten)" | ||
inspect_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
echo "# this file is located in 'src/upload_command.sh'" | ||
echo "# code for 'cli upload' goes here" | ||
echo "# you can edit it freely and regenerate (it will not be overwritten)" | ||
inspect_args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f ./src/*.sh | ||
|
||
set -x | ||
|
||
bashly generate | ||
|
||
### Try Me ### | ||
|
||
./cli download | ||
./cli upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if Settings.show_examples_on_error && examples.any? | ||
= view_marker | ||
|
||
> printf "{{ strings[:examples_caption_on_error] }}\n" >&2 | ||
examples.each do |example| | ||
> printf "{{ example.wrap(78).indent(2).sanitize_for_print }}\n" >&2 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
+ bashly generate | ||
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 [TARGET] [OPTIONS] | ||
examples: | ||
cli download example.com | ||
cli download example.com ./output -f | ||
+ ./cli upload | ||
missing required argument: SOURCE | ||
usage: cli upload SOURCE [OPTIONS] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters