|
| 1 | +# Command Paths Example |
| 2 | + |
| 3 | +Demonstrates how to globally change the path used for command files and instruct |
| 4 | +bashly to read/write command files to nested sub-directories. |
| 5 | + |
| 6 | +This is useful for scripts with many commands, |
| 7 | + |
| 8 | +Note that the specified path is relative to the `src` folder. |
| 9 | + |
| 10 | +See also: [Command Filenames Example](/examples/command-filenames#readme) |
| 11 | + |
| 12 | +This example was generated with: |
| 13 | + |
| 14 | +```bash |
| 15 | +$ bashly init |
| 16 | +$ bashly add settings |
| 17 | +# ... now edit src/settings.yml to match the example ... |
| 18 | +$ bashly generate |
| 19 | +``` |
| 20 | + |
| 21 | +<!-- include: settings.yml --> |
| 22 | + |
| 23 | +----- |
| 24 | + |
| 25 | +## `bashly.yml` |
| 26 | + |
| 27 | +```yaml |
| 28 | +name: cli |
| 29 | +help: Sample application |
| 30 | +version: 0.1.0 |
| 31 | + |
| 32 | +environment_variables: |
| 33 | +- name: api_key |
| 34 | + help: Set your API key |
| 35 | + |
| 36 | +commands: |
| 37 | +- name: download |
| 38 | + alias: d |
| 39 | + help: Download a file |
| 40 | + |
| 41 | + args: |
| 42 | + - name: source |
| 43 | + required: true |
| 44 | + help: URL to download from |
| 45 | + - name: target |
| 46 | + help: "Target filename (default: same as source)" |
| 47 | + |
| 48 | + flags: |
| 49 | + - long: --force |
| 50 | + short: -f |
| 51 | + help: Overwrite existing files |
| 52 | + |
| 53 | + examples: |
| 54 | + - cli download example.com |
| 55 | + - cli download example.com ./output -f |
| 56 | + |
| 57 | + environment_variables: |
| 58 | + - name: default_target_location |
| 59 | + help: Set the default location to download to |
| 60 | + |
| 61 | +- name: upload |
| 62 | + alias: u |
| 63 | + help: Upload a file |
| 64 | + args: |
| 65 | + - name: source |
| 66 | + required: true |
| 67 | + help: File to upload |
| 68 | + |
| 69 | + flags: |
| 70 | + - long: --user |
| 71 | + short: -u |
| 72 | + arg: user |
| 73 | + help: Username to use for logging in |
| 74 | + required: true |
| 75 | + - long: --password |
| 76 | + short: -p |
| 77 | + arg: password |
| 78 | + help: Password to use for logging in |
| 79 | +``` |
| 80 | +
|
| 81 | +## `settings.yml` |
| 82 | + |
| 83 | +```yaml |
| 84 | +# The path to use for command files, relative to source_dir |
| 85 | +# When set to nil (~), command files will be placed directly under source_dir |
| 86 | +# When set to any other string, command files will be placed under this |
| 87 | +# directory, and each command will get its own subdirectory |
| 88 | +
|
| 89 | +# commands_dir: ~ |
| 90 | +commands_dir: commands |
| 91 | +
|
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +## Generated script output |
| 96 | + |
| 97 | +### `$ ./cli` |
| 98 | + |
| 99 | +```shell |
| 100 | +cli - Sample application |
| 101 | +
|
| 102 | +Usage: |
| 103 | + cli COMMAND |
| 104 | + cli [COMMAND] --help | -h |
| 105 | + cli --version | -v |
| 106 | +
|
| 107 | +Commands: |
| 108 | + download Download a file |
| 109 | + upload Upload a file |
| 110 | +
|
| 111 | +
|
| 112 | +
|
| 113 | +``` |
| 114 | + |
| 115 | +### `$ ./cli -h` |
| 116 | + |
| 117 | +```shell |
| 118 | +cli - Sample application |
| 119 | +
|
| 120 | +Usage: |
| 121 | + cli COMMAND |
| 122 | + cli [COMMAND] --help | -h |
| 123 | + cli --version | -v |
| 124 | +
|
| 125 | +Commands: |
| 126 | + download Download a file |
| 127 | + upload Upload a file |
| 128 | +
|
| 129 | +Options: |
| 130 | + --help, -h |
| 131 | + Show this help |
| 132 | +
|
| 133 | + --version, -v |
| 134 | + Show version number |
| 135 | +
|
| 136 | +Environment Variables: |
| 137 | + API_KEY |
| 138 | + Set your API key |
| 139 | +
|
| 140 | +
|
| 141 | +
|
| 142 | +``` |
| 143 | + |
| 144 | +### `$ ./cli download something` |
| 145 | + |
| 146 | +```shell |
| 147 | +# this file is located in 'src/commands/download.sh' |
| 148 | +# code for 'cli download' goes here |
| 149 | +# you can edit it freely and regenerate (it will not be overwritten) |
| 150 | +args: |
| 151 | +- ${args[source]} = something |
| 152 | +
|
| 153 | +
|
| 154 | +``` |
| 155 | + |
| 156 | +### `$ ls -1 src/*` |
| 157 | + |
| 158 | +```shell |
| 159 | +src/bashly.yml |
| 160 | +
|
| 161 | +src/commands: |
| 162 | +download.sh |
| 163 | +upload.sh |
| 164 | +
|
| 165 | +
|
| 166 | +``` |
| 167 | + |
| 168 | + |
| 169 | + |
0 commit comments