diff --git a/examples/v2/config.cmdcomp.toml b/examples/v2/config.cmdcomp.toml index 37b8767..5013793 100644 --- a/examples/v2/config.cmdcomp.toml +++ b/examples/v2/config.cmdcomp.toml @@ -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." diff --git a/examples/v2/config.cmdcomp.yaml b/examples/v2/config.cmdcomp.yaml index 311df95..50f8068 100644 --- a/examples/v2/config.cmdcomp.yaml +++ b/examples/v2/config.cmdcomp.yaml @@ -71,6 +71,10 @@ root: --envname: - dev - prd + gcs: + type: delegate + description: gcs command. + target: [gcloud, storage] test: description: "test command." subcommands: diff --git a/examples/v2/output.bash b/examples/v2/output.bash index 41bb846..c0edf6a 100644 --- a/examples/v2/output.bash +++ b/examples/v2/output.bash @@ -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 )) @@ -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 @@ -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 diff --git a/examples/v2/output.zsh b/examples/v2/output.zsh index 1da9f01..918e975 100644 --- a/examples/v2/output.zsh +++ b/examples/v2/output.zsh @@ -18,6 +18,7 @@ _cliname() { cd'[cd project directory.]' scripts'[operate scripts.]' git'[git command.]' + gcs'[gcs command.]' test'[test command.]' ) @@ -85,6 +86,12 @@ _cliname() { _normal ;; + gcs) + words=(gcloud storage "${words[2, -1]}") + ((CURRENT += 1)) + _normal + ;; + test) local -a __test_subcmds __test_subcmds=(