diff --git a/Makefile b/Makefile index f38d5e46..4353052d 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,8 @@ GOARCH := $(shell go env GOARCH) endif # go.opentelemetry.io/otel/sdk/metric@v0.31.0 - there are breaking changes in v0.32.0. -# github.com/urfave/cli/v2@v2.23.6 - newer version regressed reading JSON values in subcommands. TODO apply this to subcommands https://github.com/urfave/cli/commit/dc6dfb7851fbaa6519a9691ac921c9c7e072abc8#diff-6c4b6ed7dc8834cef100f50dae61c30ffe7775a3f3f6f5a557517cb740c44a2dR237 PINNED_DEPENDENCIES := \ - go.opentelemetry.io/otel/sdk/metric@v0.31.0 \ - github.com/urfave/cli/v2@v2.23.6 + go.opentelemetry.io/otel/sdk/metric@v0.31.0 ##### Build ##### diff --git a/README.md b/README.md index e423540d..d5069692 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ See the CLI docs for a [list of env vars](https://docs.temporal.io/cli#environme The Temporal CLI has the capability to auto-complete commands. -Running `temporal completion SHELL` will output the related completion SHELL code. +Running `temporal completion SHELL` will output completion setup code for the given shell. ### zsh auto-completion @@ -187,7 +187,7 @@ If you're running auto-completion from the terminal, run the command below: echo 'source <(temporal completion zsh)' >> ~/.zshrc ``` -After setting the variable, run: +After editing the file, run: `source ~/.zshrc`. @@ -219,6 +219,12 @@ It should say `_init_completion is a function` and print the function. Enable completion for Temporal by adding the following code to your bash file: +```bash +source <(temporal completion bash) +``` + +In an existing terminal, you can do that by running: + ```bash echo 'source <(temporal completion bash)' >> ~/.bashrc source ~/.bashrc @@ -227,8 +233,8 @@ source ~/.bashrc Now test by typing `temporal`, space, and then tab twice. You should see: ```bash -$ temporal -activity completion h operator server workflow +$ temporal +activity completion h operator server workflow batch env help schedule task-queue ``` diff --git a/completion/completion.go b/completion/completion.go index bbd4fcf8..4ce1625c 100644 --- a/completion/completion.go +++ b/completion/completion.go @@ -7,45 +7,56 @@ import ( "github.com/urfave/cli/v2" ) -// taken from https://github.com/urfave/cli/blob/master/autocomplete/zsh_autocomplete -var zsh_script = ` -#compdef temporal +// taken from https://github.com/urfave/cli/blob/v2-maint/autocomplete/zsh_autocomplete +var zsh_script = `#compdef temporal _cli_zsh_autocomplete() { local -a opts local cur cur=${words[-1]} if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") else - opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") fi if [[ "${opts[1]}" != "" ]]; then _describe 'values' opts else _files fi - return } compdef _cli_zsh_autocomplete temporal ` -var bash_script = ` -#! /bin/bash +// taken from https://github.com/urfave/cli/blob/v2-maint/autocomplete/bash_autocomplete +var bash_script = `#! /bin/bash +# Macs have bash3 for which the bash-completion package doesn't include +# _init_completion. This is a minimal version of that function. +_cli_init_completion() { + COMPREPLY=() + _get_comp_words_by_ref "$@" cur prev words cword +} _cli_bash_autocomplete() { if [[ "${COMP_WORDS[0]}" != "source" ]]; then - local cur opts base + local cur opts base words COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" + if declare -F _init_completion >/dev/null 2>&1; then + _init_completion -n "=:" || return + else + _cli_init_completion -n "=:" || return + fi + words=("${words[@]:0:$cword}") if [[ "$cur" == "-"* ]]; then - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + requestComp="${words[*]} ${cur} --generate-bash-completion" else - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + requestComp="${words[*]} --generate-bash-completion" fi - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + opts=$(eval "${requestComp}" 2>/dev/null) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 fi } -complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete temporal +complete -o bashdefault -o default -F _cli_bash_autocomplete temporal ` func NewCompletionCommands() []*cli.Command { diff --git a/go.mod b/go.mod index 228918be..6cde54b3 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/temporalio/tctl-kit v0.0.0-20230328153839-577f95d16fa0 github.com/temporalio/ui-server/v2 v2.16.2 - github.com/urfave/cli/v2 v2.23.6 + github.com/urfave/cli/v2 v2.25.7 go.temporal.io/api v1.23.0 go.temporal.io/sdk v1.23.1 go.temporal.io/sdk/contrib/tools/workflowcheck v0.0.0-20230328164709-88a40de39c33 diff --git a/go.sum b/go.sum index 03a3ea24..98a5756e 100644 --- a/go.sum +++ b/go.sum @@ -1090,8 +1090,8 @@ github.com/uber/jaeger-client-go v2.22.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMW github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o= github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= -github.com/urfave/cli/v2 v2.23.6 h1:iWmtKD+prGo1nKUtLO0Wg4z9esfBM4rAV4QRLQiEmJ4= -github.com/urfave/cli/v2 v2.23.6/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= +github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=