Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc #96

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/data/jinja/v2_delegate_command_structure.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: delegate
description: command description.
aliad: cmd-alias
target: aws
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: command description.
alias: my-cmd
alias: cmd-alias
arguments:
1: {{ Argument }}
--help: {{ Argument }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: command description.
alias: my-cmd
alias: cmd-alias
arguments:
--verbose: {{ Argument }}
--help: {{ Argument }}
Expand Down
8 changes: 4 additions & 4 deletions docs/usage/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The complete configuration items are as follows.
--8<-- "docs/data/v2_app_info/v2_app_info.toml"
```

| Property | Type | Description |
| -------- | ------------------------ | --------------- |
| name | `str` | cli app name. |
| alias | `str | list[str] | None` | app name alias. |
| Property | Required | Type | Description |
| -------- | -------- | ----- | ------------- |
| name | | `str` | cli app name. |
| alias | | `str | list[str] |
49 changes: 35 additions & 14 deletions docs/usage/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,48 @@ The overall structure of the [Command](#command) is shown below.
--8<-- "docs/data/jinja/v2_positional_arguments_command_structure.yaml.jinja"
```

| Property | Required | Type | Description |
| ----------- | -------- | --------------------------- | -------------------- |
| description | | `str | None` | command description. |
| alias | | `str | list[str] | None` | command alias. |
| arguments | | `dict[str | int, Argument]` | command arguments. |

The following 3 types of `arguments` keys are available.

| Examples | Description |
| ---------------------- | ---------------------------------------------------------------------------------------------------- |
| `1`, `2` | Positional argument. |
| `"--help"`, <br>`"-v"` | Keyword argument. |
| `"*"` | Wildcard argument (The same rule applies to all positions not specified in the positional argument). |

=== "Use subcommands"

```yaml
--8<-- "docs/data/jinja/v2_subcommands_command_structure.yaml.jinja"
```

| Property | Type | Description |
| ----------- | --------------------------------- | -------------------- |
| description | `str | None` | Command description. |
| alias | `str | list[str] | None` | Command alias. |
| arguments | `dict[str | int, Argument]` | Arguments. |
| subcommands | `dict[str, Command]` | Subcommands. |
| Property | Required | Type | Description |
| ----------- | -------- | --------------------------- | -------------------- |
| description | | `str | None` | command description. |
| alias | | `str | list[str] | None` | command alias. |
| arguments | | `dict[str | int, Argument]` | command arguments. |
| subcommands | | `dict[str, Command]` | Subcommands. |

The following 3 types of `arguments` keys are available.
The following 3 types of `arguments` keys are available.

| Examples | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------- |
| `1`, `2` | Positional argument. |
| `"--help"`, `"-v"` | Keyword argument. |
| `"*"` | Wildcard argument (The same rule applies to all positions not specified in the positional argument). |
| Examples | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------- |
| `"--help"`, `"-v"` | Keyword argument. |

!!! warning
=== "Use delegate"

```yaml
--8<-- "docs/data/jinja/v2_delegate_command_structure.yaml.jinja"
```

When `subcommands` are used, the keys of the `arguments` can use only keyword argument key.
| Property | Required | Type | Description |
| ----------- | -------- | --------------------------- | -------------------- |
| type | ✅ | `Literal["delegate"]` | command type. |
| description | | `str | None` | command description. |
| alias | | `str | list[str] | None` | command alias. |
| target | ✅ | `str | list[str]` | delegate target. |
40 changes: 24 additions & 16 deletions examples/demo/config.cmdcomp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ root:
type: flag
description: "print help."
subcommands:
gcloud:
type: delegate
description: "gcloud command."
target: [gcloud]
gcs:
type: delegate
description: "gcs command."
target: [gcloud, storage]
composer-operation:
type: delegate
description: "composer operation command."
target: [gcloud, composer, operations]
git:
type: delegate
description: "git command."
target: [git]
production:
alias:
- development
subcommands:
aws:
type: delegate
description: "aws command."
target: aws
s3:
type: delegate
description: "s3 command."
target: [aws, s3]
gcloud:
type: delegate
description: "gcloud command."
target: gcloud
gcs:
type: delegate
description: "gcs command."
target: [gcloud, storage]
composer-operation:
type: delegate
description: "composer operation command."
target: [gcloud, composer, operations]
test:
description: "test command."
subcommands:
Expand Down
110 changes: 82 additions & 28 deletions examples/demo/output.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,33 @@ _mycli() {
cword=$(( cword + opts_cword + 1 ))
;;

_mycli,gcloud)
cmd="_mycli_gcloud"
_mycli,production|_mycli,development)
cmd="_mycli_production"
cword=$(( cword + opts_cword + 1 ))
;;

_mycli,gcs)
cmd="_mycli_gcs"
_mycli_production,aws)
cmd="_mycli_production_aws"
cword=$(( cword + opts_cword + 1 ))
;;

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

_mycli,git)
cmd="_mycli_git"
_mycli_production,gcloud)
cmd="_mycli_production_gcloud"
cword=$(( cword + opts_cword + 1 ))
;;

_mycli_production,gcs)
cmd="_mycli_production_gcs"
cword=$(( cword + opts_cword + 1 ))
;;

_mycli_production,composer-operation)
cmd="_mycli_production_composer_operation"
cword=$(( cword + opts_cword + 1 ))
;;

Expand Down Expand Up @@ -86,21 +96,40 @@ _mycli() {
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
elif [ $cword -eq $COMP_CWORD ] ; then
opts="gcloud gcs composer-operation git test"
opts="production development test"
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
fi

return 0
;;

_mycli_production)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]] ; then
opts=""
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
elif [ $cword -eq $COMP_CWORD ] ; then
opts="aws s3 gcloud gcs composer-operation"
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
fi

return 0
;;

_mycli_gcloud)
_mycli_production_aws)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

for ((i = 0; i < 2; i++)); do
for ((i = 0; i < 3; i++)); do
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
COMP_LINE=${COMP_LINE:1}
Expand All @@ -109,23 +138,48 @@ _mycli() {
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT -= ${#COMP_WORDS[i]}))
done
COMP_LINE="gcloud $COMP_LINE"
COMP_LINE="aws $COMP_LINE"
COMP_POINT=$((COMP_POINT + 4))
COMP_WORDS=(aws "${COMP_WORDS[4, -1]}")
COMP_CWORD=${#COMP_WORDS[@]}

_command_offset 0

return 0
;;

_mycli_production_s3)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

for ((i = 0; i < 3; i++)); do
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
COMP_LINE=${COMP_LINE:1}
((COMP_POINT--))
done
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT -= ${#COMP_WORDS[i]}))
done
COMP_LINE="aws s3 $COMP_LINE"
COMP_POINT=$((COMP_POINT + 7))
COMP_WORDS=(gcloud "${COMP_WORDS[3, -1]}")
COMP_WORDS=(aws s3 "${COMP_WORDS[4, -1]}")
COMP_CWORD=${#COMP_WORDS[@]}

_command_offset 0

return 0
;;

_mycli_gcs)
_mycli_production_gcloud)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

for ((i = 0; i < 2; i++)); do
for ((i = 0; i < 3; i++)); do
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
COMP_LINE=${COMP_LINE:1}
Expand All @@ -134,23 +188,23 @@ _mycli() {
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT -= ${#COMP_WORDS[i]}))
done
COMP_LINE="gcloud storage $COMP_LINE"
COMP_POINT=$((COMP_POINT + 15))
COMP_WORDS=(gcloud storage "${COMP_WORDS[3, -1]}")
COMP_LINE="gcloud $COMP_LINE"
COMP_POINT=$((COMP_POINT + 7))
COMP_WORDS=(gcloud "${COMP_WORDS[4, -1]}")
COMP_CWORD=${#COMP_WORDS[@]}

_command_offset 0

return 0
;;

_mycli_composer_operation)
_mycli_production_gcs)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

for ((i = 0; i < 2; i++)); do
for ((i = 0; i < 3; i++)); do
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
COMP_LINE=${COMP_LINE:1}
Expand All @@ -159,23 +213,23 @@ _mycli() {
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT -= ${#COMP_WORDS[i]}))
done
COMP_LINE="gcloud composer operations $COMP_LINE"
COMP_POINT=$((COMP_POINT + 27))
COMP_WORDS=(gcloud composer operations "${COMP_WORDS[3, -1]}")
COMP_LINE="gcloud storage $COMP_LINE"
COMP_POINT=$((COMP_POINT + 15))
COMP_WORDS=(gcloud storage "${COMP_WORDS[4, -1]}")
COMP_CWORD=${#COMP_WORDS[@]}

_command_offset 0

return 0
;;

_mycli_git)
_mycli_production_composer_operation)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
cword=$(( cword + 1 ))
done

for ((i = 0; i < 2; i++)); do
for ((i = 0; i < 3; i++)); do
for ((j = 0; j <= ${#COMP_LINE}; j++)); do
[[ $COMP_LINE == "${COMP_WORDS[i]}"* ]] && break
COMP_LINE=${COMP_LINE:1}
Expand All @@ -184,9 +238,9 @@ _mycli() {
COMP_LINE=${COMP_LINE#"${COMP_WORDS[i]}"}
((COMP_POINT -= ${#COMP_WORDS[i]}))
done
COMP_LINE="git $COMP_LINE"
COMP_POINT=$((COMP_POINT + 4))
COMP_WORDS=(git "${COMP_WORDS[3, -1]}")
COMP_LINE="gcloud composer operations $COMP_LINE"
COMP_POINT=$((COMP_POINT + 27))
COMP_WORDS=(gcloud composer operations "${COMP_WORDS[4, -1]}")
COMP_CWORD=${#COMP_WORDS[@]}

_command_offset 0
Expand Down
Loading