|
| 1 | +# Split Config Example |
| 2 | + |
| 3 | +Demonstrates how to separate your bashly.yml into several files, and load |
| 4 | +configuration data from other YAML files, or directly from a YAML front matter |
| 5 | +in your code. |
| 6 | + |
| 7 | +This example was generated with: |
| 8 | + |
| 9 | +```bash |
| 10 | +$ bashly init |
| 11 | +$ bashly generate |
| 12 | +# ... now edit all files in the src folder ... |
| 13 | +$ bashly generate |
| 14 | +``` |
| 15 | + |
| 16 | +<!-- include: src/download_command.yml src/upload_command.sh src/common_flags.yml --> |
| 17 | + |
| 18 | +----- |
| 19 | + |
| 20 | +## `bashly.yml` |
| 21 | + |
| 22 | +```yaml |
| 23 | +name: cli |
| 24 | +help: Configuration splitting example |
| 25 | +version: 0.1.0 |
| 26 | + |
| 27 | +commands: |
| 28 | + # Import a command that is defined in another YAML file |
| 29 | + - import: src/download_command.yml |
| 30 | + |
| 31 | + # Import a command that is defined in the front matter of its own shell |
| 32 | + # function. |
| 33 | + - import: src/upload_command.sh |
| 34 | +``` |
| 35 | +
|
| 36 | +## `src/download_command.yml` |
| 37 | + |
| 38 | +```yaml |
| 39 | +name: download |
| 40 | +short: d |
| 41 | +help: Download a file |
| 42 | +
|
| 43 | +args: |
| 44 | +- name: source |
| 45 | + required: true |
| 46 | + help: URL to download from |
| 47 | +- name: target |
| 48 | + help: "Target filename (default: same as source)" |
| 49 | +
|
| 50 | +flags: |
| 51 | + import: src/common_flags.yml |
| 52 | +
|
| 53 | +``` |
| 54 | + |
| 55 | +## `src/upload_command.sh` |
| 56 | + |
| 57 | +```bash |
| 58 | +# This is a YAML front matter describing the command |
| 59 | +# It is imported to bashly.yml when running "bashly generate" |
| 60 | +
|
| 61 | +name: upload |
| 62 | +short: u |
| 63 | +help: Upload a file |
| 64 | +args: |
| 65 | +- name: source |
| 66 | + required: true |
| 67 | + help: File to upload |
| 68 | +
|
| 69 | +flags: |
| 70 | + import: src/common_flags.yml |
| 71 | +
|
| 72 | +--- |
| 73 | +# Shell script starts here |
| 74 | +inspect_args |
| 75 | +
|
| 76 | +``` |
| 77 | + |
| 78 | +## `src/common_flags.yml` |
| 79 | + |
| 80 | +```yaml |
| 81 | +- long: --force |
| 82 | + short: -f |
| 83 | + help: Overwrite existing files |
| 84 | +
|
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | +## Generated script output |
| 89 | + |
| 90 | +### `$ ./cli` |
| 91 | + |
| 92 | +```shell |
| 93 | +cli - Configuration splitting example |
| 94 | +
|
| 95 | +Usage: |
| 96 | + cli [command] |
| 97 | + cli [command] --help | -h |
| 98 | + cli --version | -v |
| 99 | +
|
| 100 | +Commands: |
| 101 | + download Download a file |
| 102 | + upload Upload a file |
| 103 | +
|
| 104 | +
|
| 105 | +
|
| 106 | +``` |
| 107 | + |
| 108 | +### `$ ./cli download -h` |
| 109 | + |
| 110 | +```shell |
| 111 | +cli download - Download a file |
| 112 | +
|
| 113 | +Shortcut: d |
| 114 | +
|
| 115 | +Usage: |
| 116 | + cli download SOURCE [TARGET] [options] |
| 117 | + cli download --help | -h |
| 118 | +
|
| 119 | +Options: |
| 120 | + --help, -h |
| 121 | + Show this help |
| 122 | +
|
| 123 | + --force, -f |
| 124 | + Overwrite existing files |
| 125 | +
|
| 126 | +Arguments: |
| 127 | + SOURCE |
| 128 | + URL to download from |
| 129 | +
|
| 130 | + TARGET |
| 131 | + Target filename (default: same as source) |
| 132 | +
|
| 133 | +
|
| 134 | +
|
| 135 | +``` |
| 136 | + |
| 137 | +### `$ ./cli upload -h` |
| 138 | + |
| 139 | +```shell |
| 140 | +cli upload - Upload a file |
| 141 | +
|
| 142 | +Shortcut: u |
| 143 | +
|
| 144 | +Usage: |
| 145 | + cli upload SOURCE [options] |
| 146 | + cli upload --help | -h |
| 147 | +
|
| 148 | +Options: |
| 149 | + --help, -h |
| 150 | + Show this help |
| 151 | +
|
| 152 | + --force, -f |
| 153 | + Overwrite existing files |
| 154 | +
|
| 155 | +Arguments: |
| 156 | + SOURCE |
| 157 | + File to upload |
| 158 | +
|
| 159 | +
|
| 160 | +
|
| 161 | +``` |
| 162 | + |
| 163 | + |
| 164 | + |
0 commit comments