|
| 1 | +# Command Function Example |
| 2 | + |
| 3 | +Demonstrates how to specify a custom function name for commands. This option |
| 4 | +is used internally by bashly to determine the names of the functions for any |
| 5 | +command. |
| 6 | + |
| 7 | +Normally, this should not be modified, but in some use cases it might be |
| 8 | +necessary. One such use case, is when you have two commands that naturally |
| 9 | +evaluate to the same function name. |
| 10 | + |
| 11 | +Assuming your CLI responds to both: |
| 12 | + |
| 13 | +- `cli container-start` |
| 14 | +- `cli container start` |
| 15 | + |
| 16 | +In this case, the internal function names will both be `cli_container_start`, |
| 17 | +which might be undesirable. This is where the `function` directive comes in |
| 18 | +handy. |
| 19 | + |
| 20 | +Also note that the name specified here is just used as a base name. Bashly will |
| 21 | +generate several functions from it: |
| 22 | + |
| 23 | +- `cli_container_start_command` |
| 24 | +- `cli_container_start_usage` |
| 25 | +- and possibly more |
| 26 | + |
| 27 | +This example was generated with: |
| 28 | + |
| 29 | +```bash |
| 30 | +$ bashly init |
| 31 | +# ... now edit src/bashly.yml to match the example ... |
| 32 | +$ bashly generate |
| 33 | +``` |
| 34 | + |
| 35 | +----- |
| 36 | + |
| 37 | +## `bashly.yml` |
| 38 | + |
| 39 | +```yaml |
| 40 | +name: cli |
| 41 | +help: Sample application with custom function names |
| 42 | +version: 0.1.0 |
| 43 | + |
| 44 | +commands: |
| 45 | +- name: container-start |
| 46 | + help: Start a new container (deprecated) |
| 47 | + |
| 48 | + # Override the name of the internal functions bashly uses. This is needed |
| 49 | + # in this case since the command `container-start` and the nested command |
| 50 | + # `container start` will have the same underlying function name otherwise. |
| 51 | + function: deprecated_container_start |
| 52 | + footer: This command is deprecated, use 'container start' instead |
| 53 | + |
| 54 | +- name: container |
| 55 | + help: Container commands |
| 56 | + commands: |
| 57 | + - name: start |
| 58 | + help: Start a new container |
| 59 | +``` |
| 60 | +
|
| 61 | +
|
| 62 | +
|
| 63 | +## Generated script output |
| 64 | +
|
| 65 | +### `$ ./cli` |
| 66 | + |
| 67 | +```shell |
| 68 | +cli - Sample application with custom function names |
| 69 | +
|
| 70 | +Usage: |
| 71 | + cli COMMAND |
| 72 | + cli [COMMAND] --help | -h |
| 73 | + cli --version | -v |
| 74 | +
|
| 75 | +Commands: |
| 76 | + container-start Start a new container (deprecated) |
| 77 | + container Container commands |
| 78 | +
|
| 79 | +
|
| 80 | +
|
| 81 | +``` |
| 82 | + |
| 83 | +### `$ ./cli -h` |
| 84 | + |
| 85 | +```shell |
| 86 | +cli - Sample application with custom function names |
| 87 | +
|
| 88 | +Usage: |
| 89 | + cli COMMAND |
| 90 | + cli [COMMAND] --help | -h |
| 91 | + cli --version | -v |
| 92 | +
|
| 93 | +Commands: |
| 94 | + container-start Start a new container (deprecated) |
| 95 | + container Container commands |
| 96 | +
|
| 97 | +Options: |
| 98 | + --help, -h |
| 99 | + Show this help |
| 100 | +
|
| 101 | + --version, -v |
| 102 | + Show version number |
| 103 | +
|
| 104 | +
|
| 105 | +
|
| 106 | +``` |
| 107 | + |
| 108 | +### `$ ./cli container-start --help` |
| 109 | + |
| 110 | +```shell |
| 111 | +cli container-start - Start a new container (deprecated) |
| 112 | +
|
| 113 | +Usage: |
| 114 | + cli container-start |
| 115 | + cli container-start --help | -h |
| 116 | +
|
| 117 | +Options: |
| 118 | + --help, -h |
| 119 | + Show this help |
| 120 | +
|
| 121 | +This command is deprecated, use 'container start' instead |
| 122 | +
|
| 123 | +
|
| 124 | +
|
| 125 | +``` |
| 126 | + |
| 127 | +### `$ ./cli container start --help` |
| 128 | + |
| 129 | +```shell |
| 130 | +cli container start - Start a new container |
| 131 | +
|
| 132 | +Usage: |
| 133 | + cli container start |
| 134 | + cli container start --help | -h |
| 135 | +
|
| 136 | +Options: |
| 137 | + --help, -h |
| 138 | + Show this help |
| 139 | +
|
| 140 | +
|
| 141 | +
|
| 142 | +``` |
| 143 | + |
| 144 | + |
| 145 | + |
0 commit comments