Skip to content

Commit

Permalink
Auto-complete workflow names (#1061)
Browse files Browse the repository at this point in the history
* Auto-complete workflow names
* Use cobra revision at fe5e611709b0c57fa4a89136deaa8e1d4004d053
  • Loading branch information
dtaniwaki authored and jessesuen committed Nov 3, 2018
1 parent f2914d6 commit 76b14f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
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

0 comments on commit 76b14f5

Please sign in to comment.