Skip to content

Commit b2effa9

Browse files
committed
Add command-specific argument completions
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
1 parent f27a335 commit b2effa9

29 files changed

Lines changed: 623 additions & 123 deletions

commands/bridge_auth_addtoken.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ func newBridgeAuthAddTokenCommand() *cobra.Command {
4141

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

4951
return cmd
5052
}

commands/bridge_auth_rm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ func newBridgeAuthRm() *cobra.Command {
1616
RunE: func(cmd *cobra.Command, args []string) error {
1717
return runBridgeAuthRm(env, args)
1818
},
19-
Args: cobra.ExactArgs(1),
19+
Args: cobra.ExactArgs(1),
20+
ValidArgsFunction: completeBridgeAuth(env),
2021
}
2122

2223
return cmd

commands/bridge_auth_show.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func newBridgeAuthShow() *cobra.Command {
2121
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
2222
return runBridgeAuthShow(env, args)
2323
}),
24-
Args: cobra.ExactArgs(1),
24+
Args: cobra.ExactArgs(1),
25+
ValidArgsFunction: completeBridgeAuth(env),
2526
}
2627

2728
return cmd

commands/bridge_configure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ git bug bridge configure \
9797
flags.StringVarP(&options.name, "name", "n", "", "A distinctive name to identify the bridge")
9898
flags.StringVarP(&options.target, "target", "t", "",
9999
fmt.Sprintf("The target of the bridge. Valid values are [%s]", strings.Join(bridge.Targets(), ",")))
100+
cmd.RegisterFlagCompletionFunc("target", completeFrom(bridge.Targets()))
100101
flags.StringVarP(&options.params.URL, "url", "u", "", "The URL of the remote repository")
101102
flags.StringVarP(&options.params.BaseURL, "base-url", "b", "", "The base URL of your remote issue tracker")
102103
flags.StringVarP(&options.params.Login, "login", "l", "", "The login on your remote issue tracker")

commands/bridge_pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func newBridgePullCommand() *cobra.Command {
3232
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
3333
return runBridgePull(env, options, args)
3434
}),
35-
Args: cobra.MaximumNArgs(1),
35+
Args: cobra.MaximumNArgs(1),
36+
ValidArgsFunction: completeBridge(env),
3637
}
3738

3839
flags := cmd.Flags()

commands/bridge_push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func newBridgePushCommand() *cobra.Command {
2323
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
2424
return runBridgePush(env, args)
2525
}),
26-
Args: cobra.MaximumNArgs(1),
26+
Args: cobra.MaximumNArgs(1),
27+
ValidArgsFunction: completeBridge(env),
2728
}
2829

2930
return cmd

commands/bridge_rm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ func newBridgeRm() *cobra.Command {
1616
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
1717
return runBridgeRm(env, args)
1818
}),
19-
Args: cobra.ExactArgs(1),
19+
Args: cobra.ExactArgs(1),
20+
ValidArgsFunction: completeBridge(env),
2021
}
2122

2223
return cmd

commands/comment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func newCommentCommand() *cobra.Command {
1818
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
1919
return runComment(env, args)
2020
}),
21+
ValidArgsFunction: completeBug(env),
2122
}
2223

2324
cmd.AddCommand(newCommentAddCommand())

commands/comment_add.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func newCommentAddCommand() *cobra.Command {
2525
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
2626
return runCommentAdd(env, options, args)
2727
}),
28+
ValidArgsFunction: completeBug(env),
2829
}
2930

3031
flags := cmd.Flags()

0 commit comments

Comments
 (0)