|
| 1 | +# Command Examples on Error Example |
| 2 | + |
| 3 | +Demonstrates how to show examples whenever the user does not provide all the |
| 4 | +required arguments. |
| 5 | + |
| 6 | +This example was generated with: |
| 7 | + |
| 8 | +```bash |
| 9 | +$ bashly init |
| 10 | +# ... now edit src/bashly.yml to match the example ... |
| 11 | +$ bashly add settings |
| 12 | +# ... now edit settings.yml to match the example ... |
| 13 | +$ bashly generate |
| 14 | +``` |
| 15 | + |
| 16 | +<!-- include: settings.yml --> |
| 17 | + |
| 18 | +----- |
| 19 | + |
| 20 | +## `bashly.yml` |
| 21 | + |
| 22 | +````yaml |
| 23 | +name: cli |
| 24 | +help: Sample application |
| 25 | +version: 0.1.0 |
| 26 | + |
| 27 | +commands: |
| 28 | +- name: download |
| 29 | + alias: d |
| 30 | + help: Download a file |
| 31 | + |
| 32 | + args: |
| 33 | + - name: source |
| 34 | + required: true |
| 35 | + help: URL to download from |
| 36 | + - name: target |
| 37 | + help: "Target filename (default: same as source)" |
| 38 | + |
| 39 | + flags: |
| 40 | + - long: --force |
| 41 | + short: -f |
| 42 | + help: Overwrite existing files |
| 43 | + |
| 44 | + # Examples can be provided either as an array, or as a string. |
| 45 | + # The array form is convenient when you just want to provide one-liner |
| 46 | + # examples. |
| 47 | + examples: |
| 48 | + - cli download example.com |
| 49 | + - cli download example.com ./output -f |
| 50 | + |
| 51 | +- name: upload |
| 52 | + alias: u |
| 53 | + help: Upload a file |
| 54 | + args: |
| 55 | + - name: source |
| 56 | + required: true |
| 57 | + help: File to upload |
| 58 | + |
| 59 | + flags: |
| 60 | + - long: --user |
| 61 | + short: -u |
| 62 | + arg: user |
| 63 | + help: Username to use for logging in |
| 64 | + required: true |
| 65 | + - long: --password |
| 66 | + short: -p |
| 67 | + arg: password |
| 68 | + help: Password to use for logging in |
| 69 | + |
| 70 | + # The string form examples is useful when you wish to have more control |
| 71 | + # over how the examples are displayed. Note the use of the '|-' marker |
| 72 | + # that tells YAML to use the string as is, including the newlines it contains. |
| 73 | + examples: |- |
| 74 | + Upload a file |
| 75 | + $ cli upload profile.png -u admin -p s3cr3t |
| 76 | +
|
| 77 | + Upload a file (you will be prompted to provide a password) |
| 78 | + $ cli upload profile.png --user admin |
| 79 | +```` |
| 80 | + |
| 81 | +## `settings.yml` |
| 82 | + |
| 83 | +````yaml |
| 84 | +show_examples_on_error: true |
| 85 | + |
| 86 | +```` |
| 87 | + |
| 88 | + |
| 89 | +## Output |
| 90 | + |
| 91 | +### `$ ./cli download` |
| 92 | + |
| 93 | +````shell |
| 94 | +missing required argument: SOURCE |
| 95 | +usage: cli download SOURCE [TARGET] [OPTIONS] |
| 96 | +examples: |
| 97 | + cli download example.com |
| 98 | + cli download example.com ./output -f |
| 99 | + |
| 100 | + |
| 101 | +```` |
| 102 | + |
| 103 | +### `$ ./cli upload` |
| 104 | + |
| 105 | +````shell |
| 106 | +missing required argument: SOURCE |
| 107 | +usage: cli upload SOURCE [OPTIONS] |
| 108 | +examples: |
| 109 | + Upload a file |
| 110 | + $ cli upload profile.png -u admin -p s3cr3t |
| 111 | + |
| 112 | + Upload a file (you will be prompted to provide a password) |
| 113 | + $ cli upload profile.png --user admin |
| 114 | + |
| 115 | + |
| 116 | +```` |
| 117 | + |
| 118 | + |
| 119 | + |
0 commit comments