|
| 1 | +# Private Command Example |
| 2 | + |
| 3 | +Demonstrates how to hide a command from the commands list. |
| 4 | + |
| 5 | +This example was generated with: |
| 6 | + |
| 7 | +```bash |
| 8 | +$ bashly init |
| 9 | +# ... now edit src/bashly.yml to match the example ... |
| 10 | +$ bashly generate |
| 11 | +``` |
| 12 | + |
| 13 | +<!-- include: src/connect_command.sh --> |
| 14 | + |
| 15 | +----- |
| 16 | + |
| 17 | +## `bashly.yml` |
| 18 | + |
| 19 | +```yaml |
| 20 | +name: cli |
| 21 | +help: Sample application with private commands |
| 22 | +version: 0.1.0 |
| 23 | + |
| 24 | +commands: |
| 25 | +- name: connect |
| 26 | + short: c |
| 27 | + help: Connect to the metaverse |
| 28 | + |
| 29 | + args: |
| 30 | + - name: protocol |
| 31 | + required: true |
| 32 | + allowed: [ftp, ssh] |
| 33 | + help: Protocol to use for connection |
| 34 | + |
| 35 | +# These two commands will be hidden from the commands list, but still executable |
| 36 | +# and visible when running 'cli connect-ftp --help' or 'cli connect-ssh --help' |
| 37 | +- name: connect-ftp |
| 38 | + help: Connect via FTP |
| 39 | + private: true |
| 40 | + |
| 41 | +- name: connect-ssh |
| 42 | + help: Connect via SSH |
| 43 | + private: true |
| 44 | +``` |
| 45 | +
|
| 46 | +## `src/connect_command.sh` |
| 47 | + |
| 48 | +```bash |
| 49 | +# Execute a subsequent (private) command based on the PROTOCOL argument |
| 50 | +protocol=${args[protocol]} |
| 51 | +cmd="./cli connect-$protocol" |
| 52 | +echo "=== Calling $cmd" |
| 53 | +$cmd |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | +## Generated script output |
| 58 | + |
| 59 | +### `$ ./cli` |
| 60 | + |
| 61 | +```shell |
| 62 | +cli - Sample application with private commands |
| 63 | +
|
| 64 | +Usage: |
| 65 | + cli [command] |
| 66 | + cli [command] --help | -h |
| 67 | + cli --version | -v |
| 68 | +
|
| 69 | +Commands: |
| 70 | + connect Connect to the metaverse |
| 71 | +
|
| 72 | +
|
| 73 | +
|
| 74 | +``` |
| 75 | + |
| 76 | +### `$ ./cli -h` |
| 77 | + |
| 78 | +```shell |
| 79 | +cli - Sample application with private commands |
| 80 | +
|
| 81 | +Usage: |
| 82 | + cli [command] |
| 83 | + cli [command] --help | -h |
| 84 | + cli --version | -v |
| 85 | +
|
| 86 | +Commands: |
| 87 | + connect Connect to the metaverse |
| 88 | +
|
| 89 | +Options: |
| 90 | + --help, -h |
| 91 | + Show this help |
| 92 | +
|
| 93 | + --version, -v |
| 94 | + Show version number |
| 95 | +
|
| 96 | +
|
| 97 | +
|
| 98 | +``` |
| 99 | + |
| 100 | +### `$ ./cli connect ftp` |
| 101 | + |
| 102 | +```shell |
| 103 | +=== Calling ./cli connect-ftp |
| 104 | +# this file is located in 'src/connect_ftp_command.sh' |
| 105 | +# code for 'cli connect-ftp' goes here |
| 106 | +# you can edit it freely and regenerate (it will not be overwritten) |
| 107 | +args: none |
| 108 | +
|
| 109 | +
|
| 110 | +``` |
| 111 | + |
| 112 | +### `$ ./cli connect-ssh` |
| 113 | + |
| 114 | +```shell |
| 115 | +# this file is located in 'src/connect_ssh_command.sh' |
| 116 | +# code for 'cli connect-ssh' goes here |
| 117 | +# you can edit it freely and regenerate (it will not be overwritten) |
| 118 | +args: none |
| 119 | +
|
| 120 | +
|
| 121 | +``` |
| 122 | + |
| 123 | +### `$ ./cli connect-ftp --help` |
| 124 | + |
| 125 | +```shell |
| 126 | +cli connect-ftp - Connect via FTP |
| 127 | +
|
| 128 | +Usage: |
| 129 | + cli connect-ftp |
| 130 | + cli connect-ftp --help | -h |
| 131 | +
|
| 132 | +Options: |
| 133 | + --help, -h |
| 134 | + Show this help |
| 135 | +
|
| 136 | +
|
| 137 | +
|
| 138 | +``` |
| 139 | + |
| 140 | + |
| 141 | + |
0 commit comments