|
| 1 | +# Reusable Flags Example |
| 2 | + |
| 3 | +Demonstrates how to use YAML anchors to apply the same flags to multiple |
| 4 | +commands. Note that this is a standard YAML feature, and is not bashly specific. |
| 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 generate |
| 12 | +``` |
| 13 | + |
| 14 | +----- |
| 15 | + |
| 16 | +## `bashly.yml` |
| 17 | + |
| 18 | +```yaml |
| 19 | +name: cli |
| 20 | +help: Sample application |
| 21 | +version: 0.1.0 |
| 22 | + |
| 23 | +commands: |
| 24 | +- name: download |
| 25 | + help: Download a file |
| 26 | + |
| 27 | + # Label these flags (&force, &debug) so we can reference it later |
| 28 | + flags: |
| 29 | + - &force |
| 30 | + long: --force |
| 31 | + short: -f |
| 32 | + help: Overwrite existing files |
| 33 | + |
| 34 | + - &debug |
| 35 | + long: --debug |
| 36 | + short: -d |
| 37 | + help: Show debug information |
| 38 | + |
| 39 | +- name: upload |
| 40 | + help: Upload a file |
| 41 | + |
| 42 | + # Reuse previously defined flags, and then add new ones |
| 43 | + flags: |
| 44 | + - *force |
| 45 | + - *debug |
| 46 | + - long: --password |
| 47 | + short: -p |
| 48 | + arg: password |
| 49 | + help: Password to use for logging in |
| 50 | +``` |
| 51 | +
|
| 52 | +
|
| 53 | +
|
| 54 | +## Generated script output |
| 55 | +
|
| 56 | +### `$ ./cli -h` |
| 57 | + |
| 58 | +```shell |
| 59 | +cli - Sample application |
| 60 | +
|
| 61 | +Usage: |
| 62 | + cli COMMAND |
| 63 | + cli [COMMAND] --help | -h |
| 64 | + cli --version | -v |
| 65 | +
|
| 66 | +Commands: |
| 67 | + download Download a file |
| 68 | + upload Upload a file |
| 69 | +
|
| 70 | +Options: |
| 71 | + --help, -h |
| 72 | + Show this help |
| 73 | +
|
| 74 | + --version, -v |
| 75 | + Show version number |
| 76 | +
|
| 77 | +
|
| 78 | +
|
| 79 | +``` |
| 80 | + |
| 81 | +### `$ ./cli download -h` |
| 82 | + |
| 83 | +```shell |
| 84 | +cli download - Download a file |
| 85 | +
|
| 86 | +Usage: |
| 87 | + cli download [OPTIONS] |
| 88 | + cli download --help | -h |
| 89 | +
|
| 90 | +Options: |
| 91 | + --help, -h |
| 92 | + Show this help |
| 93 | +
|
| 94 | + --force, -f |
| 95 | + Overwrite existing files |
| 96 | +
|
| 97 | + --debug, -d |
| 98 | + Show debug information |
| 99 | +
|
| 100 | +
|
| 101 | +
|
| 102 | +``` |
| 103 | + |
| 104 | +### `$ ./cli upload -h` |
| 105 | + |
| 106 | +```shell |
| 107 | +cli upload - Upload a file |
| 108 | +
|
| 109 | +Usage: |
| 110 | + cli upload [OPTIONS] |
| 111 | + cli upload --help | -h |
| 112 | +
|
| 113 | +Options: |
| 114 | + --help, -h |
| 115 | + Show this help |
| 116 | +
|
| 117 | + --force, -f |
| 118 | + Overwrite existing files |
| 119 | +
|
| 120 | + --debug, -d |
| 121 | + Show debug information |
| 122 | +
|
| 123 | + --password, -p PASSWORD |
| 124 | + Password to use for logging in |
| 125 | +
|
| 126 | +
|
| 127 | +
|
| 128 | +``` |
| 129 | + |
| 130 | +### `$ ./cli upload --force` |
| 131 | + |
| 132 | +```shell |
| 133 | +# this file is located in 'src/upload_command.sh' |
| 134 | +# code for 'cli upload' goes here |
| 135 | +# you can edit it freely and regenerate (it will not be overwritten) |
| 136 | +args: |
| 137 | +- ${args[--force]} = 1 |
| 138 | +
|
| 139 | +
|
| 140 | +``` |
| 141 | + |
| 142 | +### `$ ./cli download --debug` |
| 143 | + |
| 144 | +```shell |
| 145 | +# this file is located in 'src/download_command.sh' |
| 146 | +# code for 'cli download' goes here |
| 147 | +# you can edit it freely and regenerate (it will not be overwritten) |
| 148 | +args: |
| 149 | +- ${args[--debug]} = 1 |
| 150 | +
|
| 151 | +
|
| 152 | +``` |
| 153 | + |
| 154 | + |
| 155 | + |
0 commit comments