Skip to content

Commit 5690c4a

Browse files
committed
- Change the group option so that it no longer lingers
1 parent 651d866 commit 5690c4a

File tree

11 files changed

+336
-49
lines changed

11 files changed

+336
-49
lines changed

examples/command-groups/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ commands:
2525
- name: download
2626
help: Download a file
2727

28-
# By specifying a group, the `download` comnmand (and all subsequent
29-
# commands until the next `group`) will be printed under this `File`
30-
# caption.
28+
# By specifying a group, the `download` comnmand will be printed under
29+
# this `File` caption.
3130
group: File
3231

3332
args:
@@ -37,6 +36,7 @@ commands:
3736

3837
- name: upload
3938
help: Upload a file
39+
group: File
4040

4141
args:
4242
- name: file
@@ -46,12 +46,12 @@ commands:
4646
- name: login
4747
help: Write login credentials to the config file
4848

49-
# The `login` command (and all subsequent commands) will be printed under
50-
# the `Login` caption.
49+
# The `login` command will be printed under the `Login` caption.
5150
group: Login
5251

5352
- name: logout
5453
help: Delete login credentials to the config file
54+
group: Login
5555
```
5656
5757
@@ -70,11 +70,13 @@ Usage:
7070
7171
File Commands:
7272
download Download a file
73+
74+
Commands:
7375
upload Upload a file
76+
logout Delete login credentials to the config file
7477
7578
Login Commands:
7679
login Write login credentials to the config file
77-
logout Delete login credentials to the config file
7880
7981
8082
@@ -92,11 +94,13 @@ Usage:
9294
9395
File Commands:
9496
download Download a file
97+
98+
Commands:
9599
upload Upload a file
100+
logout Delete login credentials to the config file
96101
97102
Login Commands:
98103
login Write login credentials to the config file
99-
logout Delete login credentials to the config file
100104
101105
Options:
102106
--help, -h

examples/command-groups/src/bashly.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ commands:
66
- name: download
77
help: Download a file
88

9-
# By specifying a group, the `download` comnmand (and all subsequent
10-
# commands until the next `group`) will be printed under this `File`
11-
# caption.
9+
# By specifying a group, the `download` comnmand will be printed under
10+
# this `File` caption.
1211
group: File
1312

1413
args:
@@ -18,6 +17,7 @@ commands:
1817

1918
- name: upload
2019
help: Upload a file
20+
group: File
2121

2222
args:
2323
- name: file
@@ -27,10 +27,10 @@ commands:
2727
- name: login
2828
help: Write login credentials to the config file
2929

30-
# The `login` command (and all subsequent commands) will be printed under
31-
# the `Login` caption.
30+
# The `login` command will be printed under the `Login` caption.
3231
group: Login
3332

3433
- name: logout
3534
help: Delete login credentials to the config file
35+
group: Login
3636

examples/command-private/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Usage:
6767
cli --version | -v
6868
6969
Commands:
70-
connect Connect to the metaverse
70+
connect Connect to the metaverse
7171
7272
7373
@@ -84,7 +84,7 @@ Usage:
8484
cli --version | -v
8585
8686
Commands:
87-
connect Connect to the metaverse
87+
connect Connect to the metaverse
8888
8989
Options:
9090
--help, -h
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cli
2+
src/*.sh
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Commands Deep Help Example
2+
3+
Demonstrates how to show the summary help of subcommands in the `--help`
4+
message of their parent command.
5+
6+
This example was generated with:
7+
8+
```bash
9+
$ bashly init
10+
# ... now edit src/bashly.yml to match the example ...
11+
$ bashly generate
12+
```
13+
14+
-----
15+
16+
## `bashly.yml`
17+
18+
```yaml
19+
name: cli
20+
21+
commands:
22+
- name: init
23+
help: Start a new project
24+
25+
- name: config
26+
help: Config management commands
27+
28+
# Setting `deep_help` to true will show the summary of the commands when
29+
# running the help for this command. In this case, `config edit` and
30+
# `config show` will be displayed when running `cli --help`.
31+
deep_help: true
32+
commands:
33+
- name: edit
34+
help: Edit config file
35+
- name: show
36+
help: Show config file
37+
38+
- name: server
39+
help: Server management commands
40+
41+
# Adding a `group` works well with `deep_help`.
42+
deep_help: true
43+
group: Cluster
44+
commands:
45+
- name: start
46+
help: Start the server
47+
- name: stop
48+
help: Stop the server
49+
50+
- name: container
51+
alias: c
52+
help: Container management commands
53+
deep_help: true
54+
group: Cluster
55+
commands:
56+
- name: exec
57+
help: Run a command in the container
58+
- name: down
59+
help: Terminate a container
60+
```
61+
62+
63+
64+
## Generated script output
65+
66+
### `$ ./cli`
67+
68+
```shell
69+
cli
70+
71+
Usage:
72+
cli [command]
73+
cli [command] --help | -h
74+
cli --version | -v
75+
76+
Commands:
77+
init Start a new project
78+
config Config management commands
79+
config edit Edit config file
80+
config show Show config file
81+
82+
Cluster Commands:
83+
server Server management commands
84+
server start Start the server
85+
server stop Stop the server
86+
container Container management commands
87+
container exec Run a command in the container
88+
container down Terminate a container
89+
90+
91+
92+
```
93+
94+
### `$ ./cli -h`
95+
96+
```shell
97+
cli
98+
99+
Usage:
100+
cli [command]
101+
cli [command] --help | -h
102+
cli --version | -v
103+
104+
Commands:
105+
init Start a new project
106+
config Config management commands
107+
config edit Edit config file
108+
config show Show config file
109+
110+
Cluster Commands:
111+
server Server management commands
112+
server start Start the server
113+
server stop Stop the server
114+
container Container management commands
115+
container exec Run a command in the container
116+
container down Terminate a container
117+
118+
Options:
119+
--help, -h
120+
Show this help
121+
122+
--version, -v
123+
Show version number
124+
125+
126+
127+
```
128+
129+
130+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: cli
2+
3+
commands:
4+
- name: init
5+
help: Start a new project
6+
7+
- name: config
8+
help: Config management commands
9+
10+
# Setting `deep_help` to true will show the summary of the commands when
11+
# running the help for this command. In this case, `config edit` and
12+
# `config show` will be displayed when running `cli --help`.
13+
deep_help: true
14+
commands:
15+
- name: edit
16+
help: Edit config file
17+
- name: show
18+
help: Show config file
19+
20+
- name: server
21+
help: Server management commands
22+
23+
# Adding a `group` works well with `deep_help`.
24+
deep_help: true
25+
group: Cluster
26+
commands:
27+
- name: start
28+
help: Start the server
29+
- name: stop
30+
help: Stop the server
31+
32+
- name: container
33+
alias: c
34+
help: Container management commands
35+
deep_help: true
36+
group: Cluster
37+
commands:
38+
- name: exec
39+
help: Run a command in the container
40+
- name: down
41+
help: Terminate a container
42+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./src/*.sh
4+
5+
set -x
6+
7+
bashly generate
8+
9+
### Try Me ###
10+
11+
./cli
12+
./cli -h

examples/completions/README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,58 @@ Options:
200200
# Modifying it manually is not recommended
201201

202202
_cli_completions() {
203-
local cur compline
204-
_init_completion -s || return
205-
cur=${COMP_WORDS[COMP_CWORD]}
206-
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
203+
local cur=${COMP_WORDS[COMP_CWORD]}
204+
local compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
207205

208206
case "$compline" in
209-
'download'*'--handler') COMPREPLY=($(compgen -W "curl wget" -- "$cur")) ;;
210-
'upload'*'--user') COMPREPLY=($(compgen -A user -- "$cur")) ;;
211-
'completions'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;
212-
'd'*'--handler') COMPREPLY=($(compgen -W "curl wget" -- "$cur")) ;;
213-
'upload'*'-u') COMPREPLY=($(compgen -A user -- "$cur")) ;;
214-
'download'*) COMPREPLY=($(compgen -A file -W "--force --handler --help -f -h" -- "$cur")) ;;
215-
'u'*'--user') COMPREPLY=($(compgen -A user -- "$cur")) ;;
216-
'upload'*) COMPREPLY=($(compgen -A directory -A user -W "--help --password --user -h -p -u CHANGELOG.md README.md" -- "$cur")) ;;
217-
'u'*'-u') COMPREPLY=($(compgen -A user -- "$cur")) ;;
218-
'd'*) COMPREPLY=($(compgen -A file -W "--force --handler --help -f -h" -- "$cur")) ;;
219-
'u'*) COMPREPLY=($(compgen -A directory -A user -W "--help --password --user -h -p -u CHANGELOG.md README.md" -- "$cur")) ;;
220-
*) COMPREPLY=($(compgen -W "--help --version -h -v completions d download u upload" -- "$cur")) ;;
207+
'download'*'--handler')
208+
COMPREPLY=($(compgen -W "curl wget" -- "$cur"))
209+
;;
210+
211+
'upload'*'--user')
212+
COMPREPLY=($(compgen -A user -- "$cur"))
213+
;;
214+
215+
'completions'*)
216+
COMPREPLY=($(compgen -W "--help -h" -- "$cur"))
217+
;;
218+
219+
'd'*'--handler')
220+
COMPREPLY=($(compgen -W "curl wget" -- "$cur"))
221+
;;
222+
223+
'upload'*'-u')
224+
COMPREPLY=($(compgen -A user -- "$cur"))
225+
;;
226+
227+
'download'*)
228+
COMPREPLY=($(compgen -A file -W "--force --handler --help -f -h" -- "$cur"))
229+
;;
230+
231+
'u'*'--user')
232+
COMPREPLY=($(compgen -A user -- "$cur"))
233+
;;
234+
235+
'upload'*)
236+
COMPREPLY=($(compgen -A directory -A user -W "--help --password --user -h -p -u CHANGELOG.md README.md" -- "$cur"))
237+
;;
238+
239+
'u'*'-u')
240+
COMPREPLY=($(compgen -A user -- "$cur"))
241+
;;
242+
243+
'd'*)
244+
COMPREPLY=($(compgen -A file -W "--force --handler --help -f -h" -- "$cur"))
245+
;;
246+
247+
'u'*)
248+
COMPREPLY=($(compgen -A directory -A user -W "--help --password --user -h -p -u CHANGELOG.md README.md" -- "$cur"))
249+
;;
250+
251+
*)
252+
COMPREPLY=($(compgen -W "--help --version -h -v completions d download u upload" -- "$cur"))
253+
;;
254+
221255
esac
222256
} &&
223257
complete -F _cli_completions cli

0 commit comments

Comments
 (0)