From 0ac973946c1699b6a2208e2c781d051957111e84 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 5 Jul 2023 23:44:21 -0700 Subject: [PATCH 1/5] Fix bash completion bugs --- completion/completion.go | 9 ++++----- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/completion/completion.go b/completion/completion.go index bbd4fcf8..715c2724 100644 --- a/completion/completion.go +++ b/completion/completion.go @@ -8,8 +8,7 @@ import ( ) // taken from https://github.com/urfave/cli/blob/master/autocomplete/zsh_autocomplete -var zsh_script = ` -#compdef temporal +var zsh_script = `#compdef temporal _cli_zsh_autocomplete() { local -a opts local cur @@ -29,8 +28,8 @@ _cli_zsh_autocomplete() { compdef _cli_zsh_autocomplete temporal ` -var bash_script = ` -#! /bin/bash +// taken from https://github.com/urfave/cli/blob/master/autocomplete/bash_autocomplete +var bash_script = `#! /bin/bash _cli_bash_autocomplete() { if [[ "${COMP_WORDS[0]}" != "source" ]]; then local cur opts base @@ -45,7 +44,7 @@ _cli_bash_autocomplete() { 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 62c637ac..60b9e94f 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 2d846238..648ecae6 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= From 9e5c64ed950a7816a8d5ec4ace096a5a52caa791 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 5 Jul 2023 23:54:41 -0700 Subject: [PATCH 2/5] update README --- README.md | 56 +++++++------------------------------------------------ 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index e423540d..c9a34cd1 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,37 +187,19 @@ 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`. ### Bash auto-completion -Bash auto-completion relies on `bash-completion`. +Enable completion for Temporal by adding the following code to your `~/.bashrc` file: -Install the software with the steps provided [here](https://github.com/scop/bash-completion#installation), or use your preferred package manager on your operating system. - -#### macOS installation - -Install `bash-completion` through Homebrew: -`brew install bash-completion@2` - -Follow the instruction printed in the "Caveats" section, which will say to add one of the following lines to your `~/.bashrc` file: - -```sh -[[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/etc/profile.d/bash_completion.sh" -``` - -or: - -```sh -[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" +```bash +source <(temporal completion bash) ``` -Verify that `bash-completion` is installed by running `type _init_completion`. -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: +In an existing terminal, you can do that and load completion by running: ```bash echo 'source <(temporal completion bash)' >> ~/.bashrc @@ -228,34 +210,10 @@ Now test by typing `temporal`, space, and then tab twice. You should see: ```bash $ temporal -activity completion h operator server workflow +activity completion h operator server workflow batch env help schedule task-queue ``` -#### Linux installation - -Use any of the following package managers to install `bash-completion`: -`apt install bash-completion` -`pacman -S bash-completion` -`yum install bash-completion` - -Verify that `bash-completion` is installed by running `type _init_completion`. - -To install the software on Alpine Linux, run: - -```bash -apk update -apk add bash-completion -source /etc/profile.d/bash_completion.sh -``` - -Finally, enable completion for Temporal by adding the following code to your bash file: - -``` -echo 'source <(temporal completion bash)' >> ~/.bashrc -source ~/.bashrc -``` - ## Development ### Compile and run CLI From c7f6f0ef37a02fd1d528dfd9d382d0af345cb07a Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 6 Jul 2023 19:58:23 -0700 Subject: [PATCH 3/5] remove pinned dependency --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 ##### From 44fd6a0fcaf7e3fce381928f57caaf923f859440 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Fri, 7 Jul 2023 09:40:53 -0700 Subject: [PATCH 4/5] partial revert README changes --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c9a34cd1..d5069692 100644 --- a/README.md +++ b/README.md @@ -193,13 +193,37 @@ After editing the file, run: ### Bash auto-completion -Enable completion for Temporal by adding the following code to your `~/.bashrc` file: +Bash auto-completion relies on `bash-completion`. + +Install the software with the steps provided [here](https://github.com/scop/bash-completion#installation), or use your preferred package manager on your operating system. + +#### macOS installation + +Install `bash-completion` through Homebrew: +`brew install bash-completion@2` + +Follow the instruction printed in the "Caveats" section, which will say to add one of the following lines to your `~/.bashrc` file: + +```sh +[[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/etc/profile.d/bash_completion.sh" +``` + +or: + +```sh +[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" +``` + +Verify that `bash-completion` is installed by running `type _init_completion`. +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 and load completion by running: +In an existing terminal, you can do that by running: ```bash echo 'source <(temporal completion bash)' >> ~/.bashrc @@ -209,11 +233,35 @@ source ~/.bashrc Now test by typing `temporal`, space, and then tab twice. You should see: ```bash -$ temporal +$ temporal activity completion h operator server workflow batch env help schedule task-queue ``` +#### Linux installation + +Use any of the following package managers to install `bash-completion`: +`apt install bash-completion` +`pacman -S bash-completion` +`yum install bash-completion` + +Verify that `bash-completion` is installed by running `type _init_completion`. + +To install the software on Alpine Linux, run: + +```bash +apk update +apk add bash-completion +source /etc/profile.d/bash_completion.sh +``` + +Finally, enable completion for Temporal by adding the following code to your bash file: + +``` +echo 'source <(temporal completion bash)' >> ~/.bashrc +source ~/.bashrc +``` + ## Development ### Compile and run CLI From e670b6f0e056ebc29884e8d8fd56ffc5facb5d48 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Fri, 7 Jul 2023 09:43:57 -0700 Subject: [PATCH 5/5] update completion scripts to the ones on the v2-maint branch of cli --- completion/completion.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/completion/completion.go b/completion/completion.go index 715c2724..4ce1625c 100644 --- a/completion/completion.go +++ b/completion/completion.go @@ -7,40 +7,52 @@ import ( "github.com/urfave/cli/v2" ) -// taken from https://github.com/urfave/cli/blob/master/autocomplete/zsh_autocomplete +// 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 ` -// taken from https://github.com/urfave/cli/blob/master/autocomplete/bash_autocomplete +// 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 }