Now that [1] is merged and released, we can use it to simplify our
completion declarations.
[1]: https://github.com/spf13/cobra/pull/1574
---
builds.go | 10 ++++------
git.go | 4 +---
go.mod | 10 +++++-----
go.sum | 22 ++++++++++++----------
lists.go | 13 +++++++++----
main.go | 4 +---
pages.go | 4 +---
todo.go | 27 ++++++++++++++++++---------
8 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/builds.go b/builds.go
index 03c191b7ce6f..05c650f4f5d2 100644
--- a/builds.go
@@ -94,12 +94,10 @@ func newBuildsSubmitCommand() *cobra.Command {
}
cmd := &cobra.Command{
- Use: "submit [manifest...]",
- Short: "Submit a build manifest",
- ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"yml", "yaml"}, cobra.ShellCompDirectiveFilterFileExt
- },
- Run: run,
+ Use: "submit [manifest...]",
+ Short: "Submit a build manifest",
+ ValidArgsFunction: cobra.FixedCompletions([]string{"yml", "yaml"}, cobra.ShellCompDirectiveFilterFileExt),
+ Run: run,
}
cmd.Flags().BoolVarP(&follow, "follow", "f", false, "follow build logs")
cmd.Flags().StringVarP(¬e, "note", "n", "", "short job description")
diff --git a/git.go b/git.go
index 124c50526b18..7d3b70d6eede 100644
--- a/git.go
+++ b/git.go
@@ -798,9 +798,7 @@ func completeRev(cmd *cobra.Command, args []string, toComplete string) ([]string
return revs, cobra.ShellCompDirectiveNoFileComp
}
-func completeAccessMode(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"RO", "RW"}, cobra.ShellCompDirectiveNoFileComp
-}
+var completeAccessMode = cobra.FixedCompletions([]string{"RO", "RW"}, cobra.ShellCompDirectiveNoFileComp)
func completeArtifacts(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
diff --git a/go.mod b/go.mod
index 921a40b4acd6..6cd8feee7259 100644
--- a/go.mod
+++ b/go.mod
@@ -6,9 +6,9 @@ require (
git.sr.ht/~emersion/go-scfg v0.0.0-20211215104734-c2c7a15d6c99
git.sr.ht/~emersion/gqlclient v0.0.0-20220202181617-4e6e9c763dd2
github.com/juju/ansiterm v0.0.0-20210929141451-8b71cc96ebdc
- github.com/spf13/cobra v1.4.0
- golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
- golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
+ github.com/spf13/cobra v1.5.0
+ golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2
+ golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
)
require (
@@ -20,8 +20,8 @@ require (
github.com/lunixbochs/vtclean v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vektah/gqlparser/v2 v2.2.0 // indirect
- golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
- golang.org/x/sys v0.0.0-20220329152356-43be30ef3008 // indirect
+ golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
+ golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
diff --git a/go.sum b/go.sum
index 81b55015d74d..62ae1e4104b7 100644
--- a/go.sum
+++ b/go.sum
@@ -47,7 +47,7 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
-github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw=
github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -140,8 +140,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
-github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
-github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
+github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
+github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -219,15 +219,15 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
-golang.org/x/net v0.0.0-20220325170049-de3da57026de h1:pZB1TWnKi+o4bENlbzAgLrEbY4RMYmUIRobMcSmfeYc=
-golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ=
+golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
-golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM=
-golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
+golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 h1:+jnHzr9VPj32ykQVai5DNahi9+NSp7yYuCsl5eAQtL0=
+golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2/go.mod h1:jaDAt6Dkxork7LmZnYtzbRWj0W47D86a3TGe0YHBvmE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -265,10 +265,12 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220329152356-43be30ef3008 h1:pq9pwoi2rjLWvmiVser/lIOgiyA3fli4M+RfGVMA7nE=
-golang.org/x/sys v0.0.0-20220329152356-43be30ef3008/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220624220833-87e55d714810 h1:rHZQSjJdAI4Xf5Qzeh2bBc5YJIkPFVM6oDtMFYmgws0=
+golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM=
+golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/lists.go b/lists.go
index b85d458e051f..069a62c6446e 100644
--- a/lists.go
+++ b/lists.go
@@ -660,10 +660,15 @@ func parsePatchID(ctx context.Context, cmd *cobra.Command, s string) (id int32,
return id, instance, nil
}
-func completePatchsetStatus(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"unknown", "proposed", "needs_revision", "superseded",
- "approved", "rejected", "applied"}, cobra.ShellCompDirectiveNoFileComp
-}
+var completePatchsetStatus = cobra.FixedCompletions([]string{
+ "unknown",
+ "proposed",
+ "needs_revision",
+ "superseded",
+ "approved",
+ "rejected",
+ "applied",
+}, cobra.ShellCompDirectiveNoFileComp)
func completePatchsetID(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
diff --git a/main.go b/main.go
index 8e7ff0600544..5156552870fa 100644
--- a/main.go
+++ b/main.go
@@ -56,9 +56,7 @@ func main() {
}
}
-func completeVisibility(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"public", "unlisted", "private"}, cobra.ShellCompDirectiveNoFileComp
-}
+var completeVisibility = cobra.FixedCompletions([]string{"public", "unlisted", "private"}, cobra.ShellCompDirectiveNoFileComp)
func getConfirmation(msg string) bool {
reader := bufio.NewReader(os.Stdin)
diff --git a/pages.go b/pages.go
index 296911ab57fd..a6dcc0143bc2 100644
--- a/pages.go
+++ b/pages.go
@@ -143,9 +143,7 @@ func newPagesListCommand() *cobra.Command {
return cmd
}
-func completeProtocol(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"https", "gemini"}, cobra.ShellCompDirectiveNoFileComp
-}
+var completeProtocol = cobra.FixedCompletions([]string{"https", "gemini"}, cobra.ShellCompDirectiveNoFileComp)
func completeDomain(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
diff --git a/todo.go b/todo.go
index f6e107357788..0326fc57494f 100644
--- a/todo.go
+++ b/todo.go
@@ -1143,15 +1143,24 @@ func completeTicketID(cmd *cobra.Command, args []string, toComplete string) ([]s
return tickets, cobra.ShellCompDirectiveNoFileComp
}
-func completeTicketStatus(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"reported", "confirmed", "in_progress", "pending", "resolved"},
- cobra.ShellCompDirectiveNoFileComp
-}
-
-func completeTicketResolution(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- return []string{"unresolved", "fixed", "implemented", "wont_fix", "by_design",
- "invalid", "duplicate", "not_our_bug"}, cobra.ShellCompDirectiveNoFileComp
-}
+var completeTicketStatus = cobra.FixedCompletions([]string{
+ "reported",
+ "confirmed",
+ "in_progress",
+ "pending",
+ "resolved",
+}, cobra.ShellCompDirectiveNoFileComp)
+
+var completeTicketResolution = cobra.FixedCompletions([]string{
+ "unresolved",
+ "fixed",
+ "implemented",
+ "wont_fix",
+ "by_design",
+ "invalid",
+ "duplicate",
+ "not_our_bug",
+}, cobra.ShellCompDirectiveNoFileComp)
func completeLabelColor(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var colors []string
--
2.36.1