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

Auto-complete workflow names #1061

Merged
merged 2 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ required = [

[[constraint]]
name = "github.com/spf13/cobra"
branch = "master"
revision = "fe5e611709b0c57fa4a89136deaa8e1d4004d053"

[[constraint]]
name = "gopkg.in/src-d/go-git.v4"
Expand Down
25 changes: 25 additions & 0 deletions cmd/argo/commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ import (
"github.com/spf13/cobra"
)

const (
bashCompletionFunc = `
__argo_get_workflow() {
local argo_out
if argo_out=$(argo list --output name 2>/dev/null); then
COMPREPLY+=( $( compgen -W "${argo_out[*]}" -- "$cur" ) )
fi
}

__argo_custom_func() {
case ${last_command} in
argo_delete | argo_get | argo_logs |\
argo_resubmit | argo_resume | argo_retry | argo_suspend |\
argo_terminate | argo_wait | argo_watch)
__argo_get_workflow
return
;;
*)
;;
esac
}
`
)

func NewCompletionCommand() *cobra.Command {
var command = &cobra.Command{
Use: "completion SHELL",
Expand All @@ -30,6 +54,7 @@ variable.
}
shell := args[0]
rootCommand := NewCommand()
rootCommand.BashCompletionFunction = bashCompletionFunc
availableCompletions := map[string]func(io.Writer) error{
"bash": rootCommand.GenBashCompletion,
"zsh": rootCommand.GenZshCompletion,
Expand Down