Skip to content

Commit 53067ba

Browse files
authored
Merge pull request #220 from DannyBen/change/short-to-alias
Rename `Command.short` to `Command.alias` and add support for multiple values
2 parents 38afb94 + a6c419d commit 53067ba

File tree

60 files changed

+540
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+540
-121
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
2929
- [repeatable-flag](repeatable-flag#readme) - allowing flags to be provided multiple times
3030
- [conflicts](conflicts#readme) - defining mutually exclusive flags
3131
- [command-private](command-private#readme) - hiding commands from the command list
32+
- [command-aliases](command-aliases#readme) - allowing a command to be called with multiple names
3233
- [stdin](stdin#readme) - reading input from stdin
3334
- [filters](filters#readme) - preventing commands from running unless custom conditions are met
3435

examples/catch-all-advanced/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ version: 0.1.0
2222

2323
commands:
2424
- name: download
25-
short: d
25+
alias: d
2626
help: Download a file
2727

2828
# Configure catch_all for the `download` sub-command using the extended
@@ -48,7 +48,7 @@ commands:
4848
- cli download example.com ./output -f
4949

5050
- name: upload
51-
short: u
51+
alias: u
5252
help: Upload a file
5353

5454
# Configure catch_all for the `upload` sub-command using the extended
@@ -87,7 +87,7 @@ Commands:
8787
```shell
8888
cli download - Download a file
8989
90-
Shortcut: d
90+
Alias: d
9191
9292
Usage:
9393
cli download SOURCE [TARGET] [options] [AWS PARAMS...]
@@ -167,7 +167,7 @@ other_args:
167167
```shell
168168
cli upload - Upload a file
169169
170-
Shortcut: u
170+
Alias: u
171171
172172
Usage:
173173
cli upload FILES...

examples/catch-all-advanced/src/bashly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 0.1.0
44

55
commands:
66
- name: download
7-
short: d
7+
alias: d
88
help: Download a file
99

1010
# Configure catch_all for the `download` sub-command using the extended
@@ -30,7 +30,7 @@ commands:
3030
- cli download example.com ./output -f
3131

3232
- name: upload
33-
short: u
33+
alias: u
3434
help: Upload a file
3535

3636
# Configure catch_all for the `upload` sub-command using the extended
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/*.sh
2+
cli

examples/command-aliases/README.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Command Aliases Example
2+
3+
Demonstrates how to set multiple aliases to a command.
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+
-----
14+
15+
## `bashly.yml`
16+
17+
```yaml
18+
name: cli
19+
help: Sample application
20+
version: 0.1.0
21+
22+
environment_variables:
23+
- name: api_key
24+
help: Set your API key
25+
26+
commands:
27+
- name: download
28+
29+
# alias the "download" command as "d"
30+
alias: d
31+
help: Download a file
32+
33+
args:
34+
- name: source
35+
required: true
36+
help: URL to download from
37+
- name: target
38+
help: "Target filename (default: same as source)"
39+
40+
examples:
41+
- cli download example.com
42+
- cli d example.com ./output
43+
44+
- name: upload
45+
46+
# alias the "upload" command as both "u" and "push"
47+
alias: [u, push]
48+
help: Upload a file
49+
args:
50+
- name: source
51+
required: true
52+
help: File to upload
53+
54+
examples:
55+
- cli upload README.md
56+
- cli push README.md
57+
- cli u README.md
58+
```
59+
60+
61+
62+
## Generated script output
63+
64+
### `$ ./cli`
65+
66+
```shell
67+
cli - Sample application
68+
69+
Usage:
70+
cli [command]
71+
cli [command] --help | -h
72+
cli --version | -v
73+
74+
Commands:
75+
download Download a file
76+
upload Upload a file
77+
78+
79+
80+
```
81+
82+
### `$ ./cli -h`
83+
84+
```shell
85+
cli - Sample application
86+
87+
Usage:
88+
cli [command]
89+
cli [command] --help | -h
90+
cli --version | -v
91+
92+
Commands:
93+
download Download a file
94+
upload Upload a file
95+
96+
Options:
97+
--help, -h
98+
Show this help
99+
100+
--version, -v
101+
Show version number
102+
103+
Environment Variables:
104+
API_KEY
105+
Set your API key
106+
107+
108+
109+
```
110+
111+
### `$ ./cli download -h`
112+
113+
```shell
114+
cli download - Download a file
115+
116+
Alias: d
117+
118+
Usage:
119+
cli download SOURCE [TARGET]
120+
cli download --help | -h
121+
122+
Options:
123+
--help, -h
124+
Show this help
125+
126+
Arguments:
127+
SOURCE
128+
URL to download from
129+
130+
TARGET
131+
Target filename (default: same as source)
132+
133+
Examples:
134+
cli download example.com
135+
cli d example.com ./output
136+
137+
138+
139+
```
140+
141+
### `$ ./cli d somefile`
142+
143+
```shell
144+
# this file is located in 'src/download_command.sh'
145+
# code for 'cli download' goes here
146+
# you can edit it freely and regenerate (it will not be overwritten)
147+
args:
148+
- ${args[source]} = somefile
149+
150+
151+
```
152+
153+
### `$ ./cli upload --help`
154+
155+
```shell
156+
cli upload - Upload a file
157+
158+
Alias: u, push
159+
160+
Usage:
161+
cli upload SOURCE
162+
cli upload --help | -h
163+
164+
Options:
165+
--help, -h
166+
Show this help
167+
168+
Arguments:
169+
SOURCE
170+
File to upload
171+
172+
Examples:
173+
cli upload README.md
174+
cli push README.md
175+
cli u README.md
176+
177+
178+
179+
```
180+
181+
### `$ ./cli u --help`
182+
183+
```shell
184+
cli upload - Upload a file
185+
186+
Alias: u, push
187+
188+
Usage:
189+
cli upload SOURCE
190+
cli upload --help | -h
191+
192+
Options:
193+
--help, -h
194+
Show this help
195+
196+
Arguments:
197+
SOURCE
198+
File to upload
199+
200+
Examples:
201+
cli upload README.md
202+
cli push README.md
203+
cli u README.md
204+
205+
206+
207+
```
208+
209+
### `$ ./cli push somefile`
210+
211+
```shell
212+
# this file is located in 'src/upload_command.sh'
213+
# code for 'cli upload' goes here
214+
# you can edit it freely and regenerate (it will not be overwritten)
215+
args:
216+
- ${args[source]} = somefile
217+
218+
219+
```
220+
221+
222+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: cli
2+
help: Sample application
3+
version: 0.1.0
4+
5+
environment_variables:
6+
- name: api_key
7+
help: Set your API key
8+
9+
commands:
10+
- name: download
11+
12+
# alias the "download" command as "d"
13+
alias: d
14+
help: Download a file
15+
16+
args:
17+
- name: source
18+
required: true
19+
help: URL to download from
20+
- name: target
21+
help: "Target filename (default: same as source)"
22+
23+
examples:
24+
- cli download example.com
25+
- cli d example.com ./output
26+
27+
- name: upload
28+
29+
# alias the "upload" command as both "u" and "push"
30+
alias: [u, push]
31+
help: Upload a file
32+
args:
33+
- name: source
34+
required: true
35+
help: File to upload
36+
37+
examples:
38+
- cli upload README.md
39+
- cli push README.md
40+
- cli u README.md

examples/command-aliases/test.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# Cleanup before testing
4+
rm -f src/*.sh
5+
6+
set -x
7+
8+
bashly generate
9+
10+
### Try Me ###
11+
12+
./cli
13+
./cli -h
14+
./cli download -h
15+
./cli d somefile
16+
./cli upload --help
17+
./cli u --help
18+
./cli push somefile
19+
20+

examples/command-default/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ version: 0.1.0
2222

2323
commands:
2424
- name: upload
25-
short: u
25+
alias: u
2626
help: Upload a file
2727

2828
# By setting the `upload` command as the default command, it will be executed
@@ -36,7 +36,7 @@ commands:
3636
help: File to upload
3737

3838
- name: download
39-
short: d
39+
alias: d
4040
help: Download a file
4141

4242
args:

examples/command-default/src/bashly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 0.1.0
44

55
commands:
66
- name: upload
7-
short: u
7+
alias: u
88
help: Upload a file
99

1010
# By setting the `upload` command as the default command, it will be executed
@@ -18,7 +18,7 @@ commands:
1818
help: File to upload
1919

2020
- name: download
21-
short: d
21+
alias: d
2222
help: Download a file
2323

2424
args:

0 commit comments

Comments
 (0)