Skip to content

Commit 3e1451a

Browse files
authored
Merge pull request #96 from yassun7010/update_doc
Update doc
2 parents 08ec182 + 3a3b74d commit 3e1451a

File tree

8 files changed

+202
-87
lines changed

8 files changed

+202
-87
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type: delegate
2+
description: command description.
3+
aliad: cmd-alias
4+
target: aws

docs/data/jinja/v2_positional_arguments_command_structure.yaml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: command description.
2-
alias: my-cmd
2+
alias: cmd-alias
33
arguments:
44
1: {{ Argument }}
55
--help: {{ Argument }}

docs/data/jinja/v2_subcommands_command_structure.yaml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
description: command description.
2-
alias: my-cmd
2+
alias: cmd-alias
33
arguments:
44
--verbose: {{ Argument }}
55
--help: {{ Argument }}

docs/usage/app.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The complete configuration items are as follows.
1515
--8<-- "docs/data/v2_app_info/v2_app_info.toml"
1616
```
1717

18-
| Property | Type | Description |
19-
| -------- | ------------------------ | --------------- |
20-
| name | `str` | cli app name. |
21-
| alias | `str | list[str] | None` | app name alias. |
18+
| Property | Required | Type | Description |
19+
| -------- | -------- | ----- | ------------- |
20+
| name | | `str` | cli app name. |
21+
| alias | | `str | list[str] |

docs/usage/command.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,48 @@ The overall structure of the [Command](#command) is shown below.
1212
--8<-- "docs/data/jinja/v2_positional_arguments_command_structure.yaml.jinja"
1313
```
1414

15+
| Property | Required | Type | Description |
16+
| ----------- | -------- | --------------------------- | -------------------- |
17+
| description | | `str | None` | command description. |
18+
| alias | | `str | list[str] | None` | command alias. |
19+
| arguments | | `dict[str | int, Argument]` | command arguments. |
20+
21+
The following 3 types of `arguments` keys are available.
22+
23+
| Examples | Description |
24+
| ---------------------- | ---------------------------------------------------------------------------------------------------- |
25+
| `1`, `2` | Positional argument. |
26+
| `"--help"`, <br>`"-v"` | Keyword argument. |
27+
| `"*"` | Wildcard argument (The same rule applies to all positions not specified in the positional argument). |
28+
1529
=== "Use subcommands"
1630

1731
```yaml
1832
--8<-- "docs/data/jinja/v2_subcommands_command_structure.yaml.jinja"
1933
```
2034

21-
| Property | Type | Description |
22-
| ----------- | --------------------------------- | -------------------- |
23-
| description | `str | None` | Command description. |
24-
| alias | `str | list[str] | None` | Command alias. |
25-
| arguments | `dict[str | int, Argument]` | Arguments. |
26-
| subcommands | `dict[str, Command]` | Subcommands. |
35+
| Property | Required | Type | Description |
36+
| ----------- | -------- | --------------------------- | -------------------- |
37+
| description | | `str | None` | command description. |
38+
| alias | | `str | list[str] | None` | command alias. |
39+
| arguments | | `dict[str | int, Argument]` | command arguments. |
40+
| subcommands | | `dict[str, Command]` | Subcommands. |
2741

28-
The following 3 types of `arguments` keys are available.
42+
The following 3 types of `arguments` keys are available.
2943

30-
| Examples | Description |
31-
| ------------------ | ----------------------------------------------------------------------------------------------------- |
32-
| `1`, `2` | Positional argument. |
33-
| `"--help"`, `"-v"` | Keyword argument. |
34-
| `"*"` | Wildcard argument (The same rule applies to all positions not specified in the positional argument). |
44+
| Examples | Description |
45+
| ------------------ | ---------------------------------------------------------------------------------------------------- |
46+
| `"--help"`, `"-v"` | Keyword argument. |
3547

36-
!!! warning
48+
=== "Use delegate"
49+
50+
```yaml
51+
--8<-- "docs/data/jinja/v2_delegate_command_structure.yaml.jinja"
52+
```
3753

38-
When `subcommands` are used, the keys of the `arguments` can use only keyword argument key.
54+
| Property | Required | Type | Description |
55+
| ----------- | -------- | --------------------------- | -------------------- |
56+
| type | ✅ | `Literal["delegate"]` | command type. |
57+
| description | | `str | None` | command description. |
58+
| alias | | `str | list[str] | None` | command alias. |
59+
| target | ✅ | `str | list[str]` | delegate target. |

examples/demo/config.cmdcomp.yaml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@ root:
1111
type: flag
1212
description: "print help."
1313
subcommands:
14-
gcloud:
15-
type: delegate
16-
description: "gcloud command."
17-
target: [gcloud]
18-
gcs:
19-
type: delegate
20-
description: "gcs command."
21-
target: [gcloud, storage]
22-
composer-operation:
23-
type: delegate
24-
description: "composer operation command."
25-
target: [gcloud, composer, operations]
26-
git:
27-
type: delegate
28-
description: "git command."
29-
target: [git]
14+
production:
15+
alias:
16+
- development
17+
subcommands:
18+
aws:
19+
type: delegate
20+
description: "aws command."
21+
target: aws
22+
s3:
23+
type: delegate
24+
description: "s3 command."
25+
target: [aws, s3]
26+
gcloud:
27+
type: delegate
28+
description: "gcloud command."
29+
target: gcloud
30+
gcs:
31+
type: delegate
32+
description: "gcs command."
33+
target: [gcloud, storage]
34+
composer-operation:
35+
type: delegate
36+
description: "composer operation command."
37+
target: [gcloud, composer, operations]
3038
test:
3139
description: "test command."
3240
subcommands:

examples/demo/output.bash

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,33 @@ _mycli() {
2020
cword=$(( cword + opts_cword + 1 ))
2121
;;
2222

23-
_mycli,gcloud)
24-
cmd="_mycli_gcloud"
23+
_mycli,production|_mycli,development)
24+
cmd="_mycli_production"
2525
cword=$(( cword + opts_cword + 1 ))
2626
;;
2727

28-
_mycli,gcs)
29-
cmd="_mycli_gcs"
28+
_mycli_production,aws)
29+
cmd="_mycli_production_aws"
3030
cword=$(( cword + opts_cword + 1 ))
3131
;;
3232

33-
_mycli,composer-operation)
34-
cmd="_mycli_composer_operation"
33+
_mycli_production,s3)
34+
cmd="_mycli_production_s3"
3535
cword=$(( cword + opts_cword + 1 ))
3636
;;
3737

38-
_mycli,git)
39-
cmd="_mycli_git"
38+
_mycli_production,gcloud)
39+
cmd="_mycli_production_gcloud"
40+
cword=$(( cword + opts_cword + 1 ))
41+
;;
42+
43+
_mycli_production,gcs)
44+
cmd="_mycli_production_gcs"
45+
cword=$(( cword + opts_cword + 1 ))
46+
;;
47+
48+
_mycli_production,composer-operation)
49+
cmd="_mycli_production_composer_operation"
4050
cword=$(( cword + opts_cword + 1 ))
4151
;;
4252

@@ -86,21 +96,40 @@ _mycli() {
8696
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
8797
return 0
8898
elif [ $cword -eq $COMP_CWORD ] ; then
89-
opts="gcloud gcs composer-operation git test"
99+
opts="production development test"
100+
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
101+
return 0
102+
fi
103+
104+
return 0
105+
;;
106+
107+
_mycli_production)
108+
cmd_cword=$cword
109+
while [ $cword -lt $COMP_CWORD ] ; do
110+
cword=$(( cword + 1 ))
111+
done
112+
113+
if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]] ; then
114+
opts=""
115+
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
116+
return 0
117+
elif [ $cword -eq $COMP_CWORD ] ; then
118+
opts="aws s3 gcloud gcs composer-operation"
90119
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
91120
return 0
92121
fi
93122

94123
return 0
95124
;;
96125

97-
_mycli_gcloud)
126+
_mycli_production_aws)
98127
cmd_cword=$cword
99128
while [ $cword -lt $COMP_CWORD ] ; do
100129
cword=$(( cword + 1 ))
101130
done
102131

103-
for ((i = 0; i < 2; i++)); do
132+
for ((i = 0; i < 3; i++)); do
104133
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
105134
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
106135
COMP_LINE=${COMP_LINE:1}
@@ -109,23 +138,48 @@ _mycli() {
109138
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
110139
((COMP_POINT -= ${#COMP_WORDS[i]}))
111140
done
112-
COMP_LINE="gcloud $COMP_LINE"
141+
COMP_LINE="aws $COMP_LINE"
142+
COMP_POINT=$((COMP_POINT + 4))
143+
COMP_WORDS=(aws "${COMP_WORDS[4, -1]}")
144+
COMP_CWORD=${#COMP_WORDS[@]}
145+
146+
_command_offset 0
147+
148+
return 0
149+
;;
150+
151+
_mycli_production_s3)
152+
cmd_cword=$cword
153+
while [ $cword -lt $COMP_CWORD ] ; do
154+
cword=$(( cword + 1 ))
155+
done
156+
157+
for ((i = 0; i < 3; i++)); do
158+
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
159+
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
160+
COMP_LINE=${COMP_LINE:1}
161+
((COMP_POINT--))
162+
done
163+
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
164+
((COMP_POINT -= ${#COMP_WORDS[i]}))
165+
done
166+
COMP_LINE="aws s3 $COMP_LINE"
113167
COMP_POINT=$((COMP_POINT + 7))
114-
COMP_WORDS=(gcloud "${COMP_WORDS[3, -1]}")
168+
COMP_WORDS=(aws s3 "${COMP_WORDS[4, -1]}")
115169
COMP_CWORD=${#COMP_WORDS[@]}
116170

117171
_command_offset 0
118172

119173
return 0
120174
;;
121175

122-
_mycli_gcs)
176+
_mycli_production_gcloud)
123177
cmd_cword=$cword
124178
while [ $cword -lt $COMP_CWORD ] ; do
125179
cword=$(( cword + 1 ))
126180
done
127181

128-
for ((i = 0; i < 2; i++)); do
182+
for ((i = 0; i < 3; i++)); do
129183
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
130184
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
131185
COMP_LINE=${COMP_LINE:1}
@@ -134,23 +188,23 @@ _mycli() {
134188
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
135189
((COMP_POINT -= ${#COMP_WORDS[i]}))
136190
done
137-
COMP_LINE="gcloud storage $COMP_LINE"
138-
COMP_POINT=$((COMP_POINT + 15))
139-
COMP_WORDS=(gcloud storage "${COMP_WORDS[3, -1]}")
191+
COMP_LINE="gcloud $COMP_LINE"
192+
COMP_POINT=$((COMP_POINT + 7))
193+
COMP_WORDS=(gcloud "${COMP_WORDS[4, -1]}")
140194
COMP_CWORD=${#COMP_WORDS[@]}
141195

142196
_command_offset 0
143197

144198
return 0
145199
;;
146200

147-
_mycli_composer_operation)
201+
_mycli_production_gcs)
148202
cmd_cword=$cword
149203
while [ $cword -lt $COMP_CWORD ] ; do
150204
cword=$(( cword + 1 ))
151205
done
152206

153-
for ((i = 0; i < 2; i++)); do
207+
for ((i = 0; i < 3; i++)); do
154208
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
155209
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
156210
COMP_LINE=${COMP_LINE:1}
@@ -159,23 +213,23 @@ _mycli() {
159213
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
160214
((COMP_POINT -= ${#COMP_WORDS[i]}))
161215
done
162-
COMP_LINE="gcloud composer operations $COMP_LINE"
163-
COMP_POINT=$((COMP_POINT + 27))
164-
COMP_WORDS=(gcloud composer operations "${COMP_WORDS[3, -1]}")
216+
COMP_LINE="gcloud storage $COMP_LINE"
217+
COMP_POINT=$((COMP_POINT + 15))
218+
COMP_WORDS=(gcloud storage "${COMP_WORDS[4, -1]}")
165219
COMP_CWORD=${#COMP_WORDS[@]}
166220

167221
_command_offset 0
168222

169223
return 0
170224
;;
171225

172-
_mycli_git)
226+
_mycli_production_composer_operation)
173227
cmd_cword=$cword
174228
while [ $cword -lt $COMP_CWORD ] ; do
175229
cword=$(( cword + 1 ))
176230
done
177231

178-
for ((i = 0; i < 2; i++)); do
232+
for ((i = 0; i < 3; i++)); do
179233
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
180234
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
181235
COMP_LINE=${COMP_LINE:1}
@@ -184,9 +238,9 @@ _mycli() {
184238
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
185239
((COMP_POINT -= ${#COMP_WORDS[i]}))
186240
done
187-
COMP_LINE="git $COMP_LINE"
188-
COMP_POINT=$((COMP_POINT + 4))
189-
COMP_WORDS=(git "${COMP_WORDS[3, -1]}")
241+
COMP_LINE="gcloud composer operations $COMP_LINE"
242+
COMP_POINT=$((COMP_POINT + 27))
243+
COMP_WORDS=(gcloud composer operations "${COMP_WORDS[4, -1]}")
190244
COMP_CWORD=${#COMP_WORDS[@]}
191245

192246
_command_offset 0

0 commit comments

Comments
 (0)