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

Fix bash completion bugs #280

Merged
merged 7 commits into from Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 7 additions & 49 deletions README.md
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions completion/completion.go
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if this is no longer the case for urfave/cli > v2.23.6 https://github.com/temporalio/cli/blob/d37f65cec42f708370ec06d3cf92088ce71eb827/Makefile#L20C147-L20C147

Since we now have e2e setup i'll likely rewrite this test with an actual workflow input

func (s *cliAppSuite) TestAcceptStringSliceArgsWithCommas() {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I just tested it and it seems to work. Should I delete the pinned dependency?

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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -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=
Expand Down