Skip to content

Commit

Permalink
chore: update examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
yassun7010 committed Apr 29, 2024
1 parent cb73b4a commit 3393477
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/v2/config.cmdcomp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ target = ["git"]
type = "select"
options = ["dev", "prd"]

[root.subcommands.gcs]
type = "delegate"
description = "gcs command."
target = ["gcloud", "storage"]

[root.subcommands.test]
description = "test command."

Expand Down
4 changes: 4 additions & 0 deletions examples/v2/config.cmdcomp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ root:
--envname:
- dev
- prd
gcs:
type: delegate
description: gcs command.
target: [gcloud, storage]
test:
description: "test command."
subcommands:
Expand Down
24 changes: 23 additions & 1 deletion examples/v2/output.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ _cliname() {
cword=$(( cword + opts_cword + 1 ))
;;

_cliname,gcs)
cmd="_cliname_gcs"
cword=$(( cword + opts_cword + 1 ))
;;

_cliname,test)
cmd="_cliname_test"
cword=$(( cword + opts_cword + 1 ))
Expand Down Expand Up @@ -125,7 +130,7 @@ _cliname() {
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
elif [ $cword -eq $COMP_CWORD ] ; then
opts="list ls cd scripts git test"
opts="list ls cd scripts git gcs test"
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
fi
Expand Down Expand Up @@ -302,6 +307,23 @@ _cliname() {
return 0
;;

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

local word=${COMP_WORDS[@]::$cmd_cword}
COMP_POINT=$((COMP_POINT + 14 - ${#word} ))
COMP_LINE="gcloud storage ${COMP_WORDS[@]:$cmd_cword}"
COMP_WORDS=($COMP_LINE)
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 ))
(( COMP_CWORD < 1 )) && COMP_CWORD=1

type "_command_offset" > /dev/null 2>&1 && _command_offset 0
return 0
;;

_cliname_test)
cmd_cword=$cword
while [ $cword -lt $COMP_CWORD ] ; do
Expand Down
7 changes: 7 additions & 0 deletions examples/v2/output.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _cliname() {
cd'[cd project directory.]'
scripts'[operate scripts.]'
git'[git command.]'
gcs'[gcs command.]'
test'[test command.]'
)

Expand Down Expand Up @@ -85,6 +86,12 @@ _cliname() {
_normal
;;

gcs)
words=(gcloud storage "${words[2, -1]}")
((CURRENT += 1))
_normal
;;

test)
local -a __test_subcmds
__test_subcmds=(
Expand Down

0 comments on commit 3393477

Please sign in to comment.