Skip to content

Commit

Permalink
Add command-specific argument completions
Browse files Browse the repository at this point in the history
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched.

Closes #493
  • Loading branch information
krobelus committed Aug 1, 2021
1 parent f27a335 commit b2effa9
Show file tree
Hide file tree
Showing 29 changed files with 623 additions and 123 deletions.
2 changes: 2 additions & 0 deletions commands/bridge_auth_addtoken.go
Expand Up @@ -41,10 +41,12 @@ func newBridgeAuthAddTokenCommand() *cobra.Command {

flags.StringVarP(&options.target, "target", "t", "",
fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ",")))
cmd.RegisterFlagCompletionFunc("target", completeFrom(bridge.Targets()))
flags.StringVarP(&options.login,
"login", "l", "", "The login in the remote bug-tracker")
flags.StringVarP(&options.user,
"user", "u", "", "The user to add the token to. Default is the current user")
cmd.RegisterFlagCompletionFunc("user", completeUser(env))

return cmd
}
Expand Down
3 changes: 2 additions & 1 deletion commands/bridge_auth_rm.go
Expand Up @@ -16,7 +16,8 @@ func newBridgeAuthRm() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return runBridgeAuthRm(env, args)
},
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeBridgeAuth(env),
}

return cmd
Expand Down
3 changes: 2 additions & 1 deletion commands/bridge_auth_show.go
Expand Up @@ -21,7 +21,8 @@ func newBridgeAuthShow() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runBridgeAuthShow(env, args)
}),
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeBridgeAuth(env),
}

return cmd
Expand Down
1 change: 1 addition & 0 deletions commands/bridge_configure.go
Expand Up @@ -97,6 +97,7 @@ git bug bridge configure \
flags.StringVarP(&options.name, "name", "n", "", "A distinctive name to identify the bridge")
flags.StringVarP(&options.target, "target", "t", "",
fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ",")))
cmd.RegisterFlagCompletionFunc("target", completeFrom(bridge.Targets()))
flags.StringVarP(&options.params.URL, "url", "u", "", "The URL of the remote repository")
flags.StringVarP(&options.params.BaseURL, "base-url", "b", "", "The base URL of your remote issue tracker")
flags.StringVarP(&options.params.Login, "login", "l", "", "The login on your remote issue tracker")
Expand Down
3 changes: 2 additions & 1 deletion commands/bridge_pull.go
Expand Up @@ -32,7 +32,8 @@ func newBridgePullCommand() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runBridgePull(env, options, args)
}),
Args: cobra.MaximumNArgs(1),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: completeBridge(env),
}

flags := cmd.Flags()
Expand Down
3 changes: 2 additions & 1 deletion commands/bridge_push.go
Expand Up @@ -23,7 +23,8 @@ func newBridgePushCommand() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runBridgePush(env, args)
}),
Args: cobra.MaximumNArgs(1),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: completeBridge(env),
}

return cmd
Expand Down
3 changes: 2 additions & 1 deletion commands/bridge_rm.go
Expand Up @@ -16,7 +16,8 @@ func newBridgeRm() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runBridgeRm(env, args)
}),
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
ValidArgsFunction: completeBridge(env),
}

return cmd
Expand Down
1 change: 1 addition & 0 deletions commands/comment.go
Expand Up @@ -18,6 +18,7 @@ func newCommentCommand() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runComment(env, args)
}),
ValidArgsFunction: completeBug(env),
}

cmd.AddCommand(newCommentAddCommand())
Expand Down
1 change: 1 addition & 0 deletions commands/comment_add.go
Expand Up @@ -25,6 +25,7 @@ func newCommentAddCommand() *cobra.Command {
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runCommentAdd(env, options, args)
}),
ValidArgsFunction: completeBug(env),
}

flags := cmd.Flags()
Expand Down

0 comments on commit b2effa9

Please sign in to comment.