diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f37a1489..9d5accc497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add support for `--rbs_out` as a `protoc_builtin` plugin (requires protoc v34.0+). - Add relevant links from CEL LSP hover documentation to either or - Skip writing unchanged output files in `buf generate` to preserve modification times +- Improve shell completions for `buf` flags with fixed value sets and file/directory arguments. ## [v1.66.1] - 2026-03-09 diff --git a/cmd/buf/buf.go b/cmd/buf/buf.go index 317514940a..d1f1dcc4cb 100644 --- a/cmd/buf/buf.go +++ b/cmd/buf/buf.go @@ -462,7 +462,14 @@ func newRootCommand(name string) *appcmd.Command { }, ModifyCobra: func(cobraCommand *cobra.Command) error { cobraCommand.AddCommand(bufcobra.NewWebpagesCommand("webpages", cobraCommand)) - return nil + return cobraCommand.RegisterFlagCompletionFunc( + "log-format", + cobra.FixedCompletions([]string{ + appext.LogFormatText.String(), + appext.LogFormatColor.String(), + appext.LogFormatJSON.String(), + }, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ) }, } } diff --git a/cmd/buf/internal/command/alpha/registry/token/tokenget/tokenget.go b/cmd/buf/internal/command/alpha/registry/token/tokenget/tokenget.go index d25c09a539..4397858f39 100644 --- a/cmd/buf/internal/command/alpha/registry/token/tokenget/tokenget.go +++ b/cmd/buf/internal/command/alpha/registry/token/tokenget/tokenget.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/pkg/connectclient" "github.com/bufbuild/buf/private/pkg/netext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -52,6 +53,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/alpha/registry/token/tokenlist/tokenlist.go b/cmd/buf/internal/command/alpha/registry/token/tokenlist/tokenlist.go index dcc0cd3437..2c5f4c0768 100644 --- a/cmd/buf/internal/command/alpha/registry/token/tokenlist/tokenlist.go +++ b/cmd/buf/internal/command/alpha/registry/token/tokenlist/tokenlist.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/pkg/connectclient" "github.com/bufbuild/buf/private/pkg/netext" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -54,6 +55,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/beta/registry/plugin/pluginpush/pluginpush.go b/cmd/buf/internal/command/beta/registry/plugin/pluginpush/pluginpush.go index 1484a99d29..dc16e4c9c4 100644 --- a/cmd/buf/internal/command/beta/registry/plugin/pluginpush/pluginpush.go +++ b/cmd/buf/internal/command/beta/registry/plugin/pluginpush/pluginpush.go @@ -47,6 +47,7 @@ import ( pkgv1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/google/go-containerregistry/pkg/v1/remote/transport" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -83,6 +84,12 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName), + ) + }, } } diff --git a/cmd/buf/internal/command/breaking/breaking.go b/cmd/buf/internal/command/breaking/breaking.go index 29ec1ed706..666e930e9f 100644 --- a/cmd/buf/internal/command/breaking/breaking.go +++ b/cmd/buf/internal/command/breaking/breaking.go @@ -38,6 +38,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/wasm" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -74,6 +75,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/build/build.go b/cmd/buf/internal/command/build/build.go index abf0448e85..d2b1cbdbe7 100644 --- a/cmd/buf/internal/command/build/build.go +++ b/cmd/buf/internal/command/build/build.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/buf/buffetch" "github.com/bufbuild/buf/private/bufpkg/bufanalysis" "github.com/bufbuild/buf/private/bufpkg/bufimage/bufimageutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -62,6 +63,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/config/configlsmodules/configlsmodules.go b/cmd/buf/internal/command/config/configlsmodules/configlsmodules.go index 9b0d9ee811..08b630e115 100644 --- a/cmd/buf/internal/command/config/configlsmodules/configlsmodules.go +++ b/cmd/buf/internal/command/config/configlsmodules/configlsmodules.go @@ -31,6 +31,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -69,6 +70,16 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return cmd.RegisterFlagCompletionFunc( + formatFlagName, + cobra.FixedCompletions([]string{ + formatPath, + formatName, + formatJSON, + }, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ) + }, } } diff --git a/cmd/buf/internal/command/config/internal/internal.go b/cmd/buf/internal/command/config/internal/internal.go index 98ca2edf33..d9977a515f 100644 --- a/cmd/buf/internal/command/config/internal/internal.go +++ b/cmd/buf/internal/command/config/internal/internal.go @@ -31,6 +31,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -66,6 +67,12 @@ func NewLSCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionRuleFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionFileVersion(cmd, versionFlagName), + ) + }, } } @@ -123,11 +130,13 @@ func (f *flags) Bind(flagSet *pflag.FlagSet) { fmt.Sprintf( "List all the rules for the given configuration version. By default, the version in the buf.yaml in the current directory is used, or the latest version otherwise (currently v2). Cannot be set if --%s is set. Must be one of %s", configuredOnlyFlagName, - xslices.Map( - bufconfig.AllFileVersions, - func(fileVersion bufconfig.FileVersion) string { - return fileVersion.String() - }, + xstrings.SliceToString( + xslices.Map( + bufconfig.AllFileVersions, + func(fileVersion bufconfig.FileVersion) string { + return fileVersion.String() + }, + ), ), ), ) diff --git a/cmd/buf/internal/command/convert/convert.go b/cmd/buf/internal/command/convert/convert.go index 24b8879b97..62d0d20feb 100644 --- a/cmd/buf/internal/command/convert/convert.go +++ b/cmd/buf/internal/command/convert/convert.go @@ -32,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufimage/bufimageutil" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/gen/data/datawkt" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -91,6 +92,9 @@ Use a module on the bsr: }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/curl/curl.go b/cmd/buf/internal/command/curl/curl.go index 633a520378..479b10655f 100644 --- a/cmd/buf/internal/command/curl/curl.go +++ b/cmd/buf/internal/command/curl/curl.go @@ -43,6 +43,7 @@ import ( "github.com/bufbuild/buf/private/pkg/verbose" "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/http3" + "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -195,6 +196,24 @@ exit code that is the gRPC code, shifted three bits to the left. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + cmd.RegisterFlagCompletionFunc( + protocolFlagName, + cobra.FixedCompletions([]string{ + connect.ProtocolConnect, + connect.ProtocolGRPC, + connect.ProtocolGRPCWeb, + }, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ), + cmd.RegisterFlagCompletionFunc( + reflectProtocolFlagName, + cobra.FixedCompletions(bufcurl.AllKnownReflectProtocolStrings, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ), + cmd.RegisterFlagCompletionFunc(headerFlagName, cobra.NoFileCompletions), + cmd.RegisterFlagCompletionFunc(reflectHeaderFlagName, cobra.NoFileCompletions), + ) + }, } } diff --git a/cmd/buf/internal/command/dep/depgraph/depgraph.go b/cmd/buf/internal/command/dep/depgraph/depgraph.go index eaa3d5f516..658c23dc79 100644 --- a/cmd/buf/internal/command/dep/depgraph/depgraph.go +++ b/cmd/buf/internal/command/dep/depgraph/depgraph.go @@ -17,6 +17,7 @@ package depgraph import ( "context" "encoding/json" + "errors" "fmt" "slices" @@ -31,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/pkg/dag" "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/uuid" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -90,6 +92,18 @@ buf dep graph | dot -Tpng >| graph.png && open graph.png }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName), + cmd.RegisterFlagCompletionFunc( + formatFlagName, + cobra.FixedCompletions([]string{ + cobra.CompletionWithDesc(dotFormatString, "Graphviz DOT"), + jsonFormatString, + }, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ), + ) + }, } } diff --git a/cmd/buf/internal/command/export/export.go b/cmd/buf/internal/command/export/export.go index e8e80fd5af..cb4c1df4a1 100644 --- a/cmd/buf/internal/command/export/export.go +++ b/cmd/buf/internal/command/export/export.go @@ -32,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -86,6 +87,12 @@ Export a git repo to a local directory. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return cmd.RegisterFlagCompletionFunc( + outputFlagName, + cobra.FixedCompletions(nil, cobra.ShellCompDirectiveFilterDirs), + ) + }, } } diff --git a/cmd/buf/internal/command/format/format.go b/cmd/buf/internal/command/format/format.go index 4bce5ec994..60818e9adc 100644 --- a/cmd/buf/internal/command/format/format.go +++ b/cmd/buf/internal/command/format/format.go @@ -35,6 +35,7 @@ import ( "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/storage/storageos" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -165,6 +166,9 @@ The -w and -o flags cannot be used together in a single invocation. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/generate/generate.go b/cmd/buf/internal/command/generate/generate.go index 8a11b6ab69..f8526e28ee 100644 --- a/cmd/buf/internal/command/generate/generate.go +++ b/cmd/buf/internal/command/generate/generate.go @@ -16,6 +16,7 @@ package generate import ( "context" + "errors" "fmt" "log/slog" "os" @@ -33,6 +34,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufimage" "github.com/bufbuild/buf/private/pkg/storage/storageos" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -384,6 +386,21 @@ Insertion points are processed in the order the plugins are specified in the tem }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName), + cmd.RegisterFlagCompletionFunc( + templateFlagName, + cobra.FixedCompletions([]string{"yaml", "yml", "json"}, cobra.ShellCompDirectiveFilterFileExt), + ), + cmd.RegisterFlagCompletionFunc( + baseOutDirPathFlagName, + cobra.FixedCompletions(nil, cobra.ShellCompDirectiveFilterDirs), + ), + cmd.RegisterFlagCompletionFunc(typeFlagName, cobra.NoFileCompletions), + cmd.RegisterFlagCompletionFunc(excludeTypeFlagName, cobra.NoFileCompletions), + ) + }, } } diff --git a/cmd/buf/internal/command/lint/lint.go b/cmd/buf/internal/command/lint/lint.go index ab7421f571..0ff63f17cc 100644 --- a/cmd/buf/internal/command/lint/lint.go +++ b/cmd/buf/internal/command/lint/lint.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufanalysis" "github.com/bufbuild/buf/private/bufpkg/bufcheck" "github.com/bufbuild/buf/private/bufpkg/bufconfig" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -55,6 +56,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionLintErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/lsfiles/lsfiles.go b/cmd/buf/internal/command/lsfiles/lsfiles.go index ffb96c7478..305a76bc80 100644 --- a/cmd/buf/internal/command/lsfiles/lsfiles.go +++ b/cmd/buf/internal/command/lsfiles/lsfiles.go @@ -32,6 +32,7 @@ import ( "github.com/bufbuild/buf/private/gen/data/datawkt" "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/uuid" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -72,6 +73,16 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return cmd.RegisterFlagCompletionFunc( + formatFlagName, + cobra.FixedCompletions([]string{ + formatText, + formatJSON, + formatImport, + }, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ) + }, } } diff --git a/cmd/buf/internal/command/mod/internal/internal.go b/cmd/buf/internal/command/mod/internal/internal.go index 0c575e43b7..2aa5a5aa8b 100644 --- a/cmd/buf/internal/command/mod/internal/internal.go +++ b/cmd/buf/internal/command/mod/internal/internal.go @@ -29,6 +29,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufcheck" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -65,6 +66,12 @@ func NewLSCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionRuleFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionFileVersion(cmd, versionFlagName), + ) + }, } } diff --git a/cmd/buf/internal/command/plugin/pluginpush/pluginpush.go b/cmd/buf/internal/command/plugin/pluginpush/pluginpush.go index c069564442..060af68b07 100644 --- a/cmd/buf/internal/command/plugin/pluginpush/pluginpush.go +++ b/cmd/buf/internal/command/plugin/pluginpush/pluginpush.go @@ -16,6 +16,7 @@ package pluginpush import ( "context" + "errors" "fmt" "os" "slices" @@ -29,6 +30,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -58,6 +60,21 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionVisibility(cmd, createVisibilityFlagName), + cmd.RegisterFlagCompletionFunc( + createTypeFlagName, + cobra.FixedCompletions(bufplugin.AllPluginTypeStrings, cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder), + ), + cmd.RegisterFlagCompletionFunc( + binaryFlagName, + cobra.FixedCompletions([]string{"wasm"}, cobra.ShellCompDirectiveFilterFileExt), + ), + cmd.RegisterFlagCompletionFunc(labelFlagName, cobra.NoFileCompletions), + cmd.RegisterFlagCompletionFunc(sourceControlURLFlagName, cobra.NoFileCompletions), + ) + }, } } diff --git a/cmd/buf/internal/command/policy/policypush/policypush.go b/cmd/buf/internal/command/policy/policypush/policypush.go index 59aea1ad7b..2bebb009f5 100644 --- a/cmd/buf/internal/command/policy/policypush/policypush.go +++ b/cmd/buf/internal/command/policy/policypush/policypush.go @@ -29,6 +29,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufpolicy/bufpolicyconfig" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/google/uuid" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -55,6 +56,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return cmd.RegisterFlagCompletionFunc(labelFlagName, cobra.NoFileCompletions) + }, } } diff --git a/cmd/buf/internal/command/push/push.go b/cmd/buf/internal/command/push/push.go index 693a2bbbfa..c89c2fd268 100644 --- a/cmd/buf/internal/command/push/push.go +++ b/cmd/buf/internal/command/push/push.go @@ -35,6 +35,7 @@ import ( "github.com/bufbuild/buf/private/pkg/git" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -79,6 +80,13 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName), + cmd.RegisterFlagCompletionFunc(labelFlagName, cobra.NoFileCompletions), + cmd.RegisterFlagCompletionFunc(sourceControlURLFlagName, cobra.NoFileCompletions), + ) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go index a88382646d..8f7fc0663a 100644 --- a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go +++ b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitaddlabel/modulecommitaddlabel.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -54,6 +55,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go index c1d919d611..c9d5b0ab4a 100644 --- a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go +++ b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitinfo/modulecommitinfo.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,6 +52,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go index 2a28f5f880..c543612853 100644 --- a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go +++ b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitlist/modulecommitlist.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -64,6 +65,9 @@ If no reference is specified, it lists all commits in this module. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go index 3dc23164cd..895b8ce374 100644 --- a/cmd/buf/internal/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go +++ b/cmd/buf/internal/command/registry/module/modulecommit/modulecommitresolve/modulecommitresolve.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulecreate/modulecreate.go b/cmd/buf/internal/command/registry/module/modulecreate/modulecreate.go index 996eb9701b..a70bac8deb 100644 --- a/cmd/buf/internal/command/registry/module/modulecreate/modulecreate.go +++ b/cmd/buf/internal/command/registry/module/modulecreate/modulecreate.go @@ -16,6 +16,7 @@ package modulecreate import ( "context" + "errors" "fmt" modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" @@ -28,6 +29,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -55,6 +57,12 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName), + ) + }, } } diff --git a/cmd/buf/internal/command/registry/module/moduleinfo/moduleinfo.go b/cmd/buf/internal/command/registry/module/moduleinfo/moduleinfo.go index 3b8094a2f8..4938a176db 100644 --- a/cmd/buf/internal/command/registry/module/moduleinfo/moduleinfo.go +++ b/cmd/buf/internal/command/registry/module/moduleinfo/moduleinfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,6 +49,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go b/cmd/buf/internal/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go index ee524b4037..0e2a93b8a2 100644 --- a/cmd/buf/internal/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go +++ b/cmd/buf/internal/command/registry/module/modulelabel/modulelabelinfo/modulelabelinfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulelabel/modulelabellist/modulelabellist.go b/cmd/buf/internal/command/registry/module/modulelabel/modulelabellist/modulelabellist.go index f6e8c7dfe5..e42f9c7400 100644 --- a/cmd/buf/internal/command/registry/module/modulelabel/modulelabellist/modulelabellist.go +++ b/cmd/buf/internal/command/registry/module/modulelabel/modulelabellist/modulelabellist.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufprint" "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -58,6 +59,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/module/modulesettings/modulesettingsupdate/modulesettingsupdate.go b/cmd/buf/internal/command/registry/module/modulesettings/modulesettingsupdate/modulesettingsupdate.go index 208d5beba3..775e5fed72 100644 --- a/cmd/buf/internal/command/registry/module/modulesettings/modulesettingsupdate/modulesettingsupdate.go +++ b/cmd/buf/internal/command/registry/module/modulesettings/modulesettingsupdate/modulesettingsupdate.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -54,6 +55,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/organization/organizationcreate/organizationcreate.go b/cmd/buf/internal/command/registry/organization/organizationcreate/organizationcreate.go index f95a443a4c..3f096e8a73 100644 --- a/cmd/buf/internal/command/registry/organization/organizationcreate/organizationcreate.go +++ b/cmd/buf/internal/command/registry/organization/organizationcreate/organizationcreate.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufprint" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiowner" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -47,6 +48,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/organization/organizationinfo/organizationinfo.go b/cmd/buf/internal/command/registry/organization/organizationinfo/organizationinfo.go index 3268bd9fe6..9fc672fe6a 100644 --- a/cmd/buf/internal/command/registry/organization/organizationinfo/organizationinfo.go +++ b/cmd/buf/internal/command/registry/organization/organizationinfo/organizationinfo.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufprint" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiowner" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -47,6 +48,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go index 9268a3c088..b2855a2fd0 100644 --- a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go +++ b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitaddlabel/plugincommitaddlabel.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -54,6 +55,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitinfo/plugincommitinfo.go b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitinfo/plugincommitinfo.go index 2729d47c70..242a7fe23b 100644 --- a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitinfo/plugincommitinfo.go +++ b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitinfo/plugincommitinfo.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,6 +52,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitlist/plugincommitlist.go b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitlist/plugincommitlist.go index 3b2452848f..a4a9970468 100644 --- a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitlist/plugincommitlist.go +++ b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitlist/plugincommitlist.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -64,6 +65,9 @@ If no reference is specified, it lists all commits in this plugin. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitresolve/plugincommitresolve.go b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitresolve/plugincommitresolve.go index 901f2b93d1..548845646c 100644 --- a/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitresolve/plugincommitresolve.go +++ b/cmd/buf/internal/command/registry/plugin/plugincommit/plugincommitresolve/plugincommitresolve.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugincreate/plugincreate.go b/cmd/buf/internal/command/registry/plugin/plugincreate/plugincreate.go index a652a0e264..3361e43ed7 100644 --- a/cmd/buf/internal/command/registry/plugin/plugincreate/plugincreate.go +++ b/cmd/buf/internal/command/registry/plugin/plugincreate/plugincreate.go @@ -16,6 +16,7 @@ package plugincreate import ( "context" + "errors" "fmt" ownerv1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/owner/v1" @@ -29,6 +30,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -65,6 +67,13 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName), + bufcli.RegisterFlagCompletionPluginType(cmd, typeFlagName), + ) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/plugininfo/plugininfo.go b/cmd/buf/internal/command/registry/plugin/plugininfo/plugininfo.go index 9e0f7e4596..28c4d3ad0e 100644 --- a/cmd/buf/internal/command/registry/plugin/plugininfo/plugininfo.go +++ b/cmd/buf/internal/command/registry/plugin/plugininfo/plugininfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,6 +49,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabelinfo/pluginlabelinfo.go b/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabelinfo/pluginlabelinfo.go index 9f2b2bae45..8300cee608 100644 --- a/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabelinfo/pluginlabelinfo.go +++ b/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabelinfo/pluginlabelinfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabellist/pluginlabellist.go b/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabellist/pluginlabellist.go index 312dd894ac..00a4e80456 100644 --- a/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabellist/pluginlabellist.go +++ b/cmd/buf/internal/command/registry/plugin/pluginlabel/pluginlabellist/pluginlabellist.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufprint" "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -58,6 +59,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/plugin/pluginsettings/pluginsettingsupdate/pluginsettingsupdate.go b/cmd/buf/internal/command/registry/plugin/pluginsettings/pluginsettingsupdate/pluginsettingsupdate.go index 68e292bc46..b0c7d3be5c 100644 --- a/cmd/buf/internal/command/registry/plugin/pluginsettings/pluginsettingsupdate/pluginsettingsupdate.go +++ b/cmd/buf/internal/command/registry/plugin/pluginsettings/pluginsettingsupdate/pluginsettingsupdate.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapiplugin" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,6 +49,9 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command { }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policycommit/policycommitaddlabel/policycommitaddlabel.go b/cmd/buf/internal/command/registry/policy/policycommit/policycommitaddlabel/policycommitaddlabel.go index d1a7455cfe..b40809a9ec 100644 --- a/cmd/buf/internal/command/registry/policy/policycommit/policycommitaddlabel/policycommitaddlabel.go +++ b/cmd/buf/internal/command/registry/policy/policycommit/policycommitaddlabel/policycommitaddlabel.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -54,6 +55,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policycommit/policycommitinfo/policycommitinfo.go b/cmd/buf/internal/command/registry/policy/policycommit/policycommitinfo/policycommitinfo.go index edb474b1c4..dbe60488c4 100644 --- a/cmd/buf/internal/command/registry/policy/policycommit/policycommitinfo/policycommitinfo.go +++ b/cmd/buf/internal/command/registry/policy/policycommit/policycommitinfo/policycommitinfo.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/uuidutil" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,6 +52,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policycommit/policycommitlist/policycommitlist.go b/cmd/buf/internal/command/registry/policy/policycommit/policycommitlist/policycommitlist.go index bef007802c..d5abdfcd8d 100644 --- a/cmd/buf/internal/command/registry/policy/policycommit/policycommitlist/policycommitlist.go +++ b/cmd/buf/internal/command/registry/policy/policycommit/policycommitlist/policycommitlist.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -64,6 +65,9 @@ If no reference is specified, it lists all commits in this policy. }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policycommit/policycommitresolve/policycommitresolve.go b/cmd/buf/internal/command/registry/policy/policycommit/policycommitresolve/policycommitresolve.go index a5fcc9125c..4d77ea3556 100644 --- a/cmd/buf/internal/command/registry/policy/policycommit/policycommitresolve/policycommitresolve.go +++ b/cmd/buf/internal/command/registry/policy/policycommit/policycommitresolve/policycommitresolve.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policycreate/policycreate.go b/cmd/buf/internal/command/registry/policy/policycreate/policycreate.go index 947e10b210..362ae509c2 100644 --- a/cmd/buf/internal/command/registry/policy/policycreate/policycreate.go +++ b/cmd/buf/internal/command/registry/policy/policycreate/policycreate.go @@ -16,6 +16,7 @@ package policycreate import ( "context" + "errors" "fmt" ownerv1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/owner/v1" @@ -28,6 +29,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -55,6 +57,12 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return errors.Join( + bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName), + bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName), + ) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policyinfo/policyinfo.go b/cmd/buf/internal/command/registry/policy/policyinfo/policyinfo.go index c5c44e5cbe..cd3cd5c583 100644 --- a/cmd/buf/internal/command/registry/policy/policyinfo/policyinfo.go +++ b/cmd/buf/internal/command/registry/policy/policyinfo/policyinfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,6 +49,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policylabel/policylabelinfo/policylabelinfo.go b/cmd/buf/internal/command/registry/policy/policylabel/policylabelinfo/policylabelinfo.go index ccff1306bb..ef0715c487 100644 --- a/cmd/buf/internal/command/registry/policy/policylabel/policylabelinfo/policylabelinfo.go +++ b/cmd/buf/internal/command/registry/policy/policylabel/policylabelinfo/policylabelinfo.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,6 +51,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policylabel/policylabellist/policylabellist.go b/cmd/buf/internal/command/registry/policy/policylabel/policylabellist/policylabellist.go index 4a99b9c3e5..e53c897819 100644 --- a/cmd/buf/internal/command/registry/policy/policylabel/policylabellist/policylabellist.go +++ b/cmd/buf/internal/command/registry/policy/policylabel/policylabellist/policylabellist.go @@ -27,6 +27,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufprint" "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -58,6 +59,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/policy/policysettings/policysettingsupdate/policysettingsupdate.go b/cmd/buf/internal/command/registry/policy/policysettings/policysettingsupdate/policysettingsupdate.go index 3ef5d09d62..e32830abf9 100644 --- a/cmd/buf/internal/command/registry/policy/policysettings/policysettingsupdate/policysettingsupdate.go +++ b/cmd/buf/internal/command/registry/policy/policysettings/policysettingsupdate/policysettingsupdate.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapipolicy" "github.com/bufbuild/buf/private/pkg/syserror" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -48,6 +49,9 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command { }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionVisibility(cmd, visibilityFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/sdk/sdkinfo/sdkinfo.go b/cmd/buf/internal/command/registry/sdk/sdkinfo/sdkinfo.go index 099430210e..e643ed3250 100644 --- a/cmd/buf/internal/command/registry/sdk/sdkinfo/sdkinfo.go +++ b/cmd/buf/internal/command/registry/sdk/sdkinfo/sdkinfo.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/gen/proto/connect/buf/alpha/registry/v1alpha1/registryv1alpha1connect" registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1" "github.com/bufbuild/buf/private/pkg/connectclient" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -122,6 +123,9 @@ In this case, the SDK version provided resolves to a different commit than the c }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/registry/whoami/whoami.go b/cmd/buf/internal/command/registry/whoami/whoami.go index d249bd521b..54b1c80786 100644 --- a/cmd/buf/internal/command/registry/whoami/whoami.go +++ b/cmd/buf/internal/command/registry/whoami/whoami.go @@ -29,6 +29,7 @@ import ( registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1" "github.com/bufbuild/buf/private/pkg/connectclient" "github.com/bufbuild/buf/private/pkg/netext" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -56,6 +57,9 @@ The argument will default to buf.build if not specified.`, }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/cmd/buf/internal/command/source/sourceedit/sourceeditdeprecate/sourceeditdeprecate.go b/cmd/buf/internal/command/source/sourceedit/sourceeditdeprecate/sourceeditdeprecate.go index 3f3692bbf9..a516ad1688 100644 --- a/cmd/buf/internal/command/source/sourceedit/sourceeditdeprecate/sourceeditdeprecate.go +++ b/cmd/buf/internal/command/source/sourceedit/sourceeditdeprecate/sourceeditdeprecate.go @@ -33,6 +33,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufanalysis" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/storage" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -98,6 +99,9 @@ Display a diff of the changes instead of rewriting files: }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionErrorFormat(cmd, errorFormatFlagName) + }, } } diff --git a/cmd/buf/internal/command/stats/stats.go b/cmd/buf/internal/command/stats/stats.go index 4cba8ab38e..3d2bcd1554 100644 --- a/cmd/buf/internal/command/stats/stats.go +++ b/cmd/buf/internal/command/stats/stats.go @@ -26,6 +26,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/pkg/protostat" "github.com/bufbuild/buf/private/pkg/protostat/protostatstorage" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -51,6 +52,9 @@ func NewCommand( }, ), BindFlags: flags.Bind, + ModifyCobra: func(cmd *cobra.Command) error { + return bufcli.RegisterFlagCompletionOutputFormat(cmd, formatFlagName) + }, } } diff --git a/go.mod b/go.mod index ee7f9fb94b..68e28f8223 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20260209202127-80ab13bee0bf.1 buf.build/gen/go/bufbuild/registry/connectrpc/go v1.19.1-20260126144947-819582968857.2 buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.36.11-20260126144947-819582968857.1 - buf.build/go/app v0.2.0 + buf.build/go/app v0.2.1-0.20260319180457-cfbf7e2b6a75 buf.build/go/bufplugin v0.9.0 buf.build/go/bufprivateusage v0.1.0 buf.build/go/protovalidate v1.1.3 diff --git a/go.sum b/go.sum index af930a6f4f..9c90b8e1c6 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.36.11-20260126144947-81 buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.36.11-20260126144947-819582968857.1/go.mod h1:1JJi9jvOqRxSMa+JxiZSm57doB+db/1WYCIa2lHfc40= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.36.11-20241007202033-cf42259fcbfc.1 h1:iGPvEJltOXUMANWf0zajcRcbiOXLD90ZwPUFvbcuv6Q= buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.36.11-20241007202033-cf42259fcbfc.1/go.mod h1:nWVKKRA29zdt4uvkjka3i/y4mkrswyWwiu0TbdX0zts= -buf.build/go/app v0.2.0 h1:NYaH13A+RzPb7M5vO8uZYZ2maBZI5+MS9A9tQm66fy8= -buf.build/go/app v0.2.0/go.mod h1:0XVOYemubVbxNXVY0DnsVgWeGkcbbAvjDa1fmhBC+Wo= +buf.build/go/app v0.2.1-0.20260319180457-cfbf7e2b6a75 h1:wb0B8XpzzfGIekqUXw4kUAvkroAiVmAg3uIpgo5S8sM= +buf.build/go/app v0.2.1-0.20260319180457-cfbf7e2b6a75/go.mod h1:0XVOYemubVbxNXVY0DnsVgWeGkcbbAvjDa1fmhBC+Wo= buf.build/go/bufplugin v0.9.0 h1:ktZJNP3If7ldcWVqh46XKeiYJVPxHQxCfjzVQDzZ/lo= buf.build/go/bufplugin v0.9.0/go.mod h1:Z0CxA3sKQ6EPz/Os4kJJneeRO6CjPeidtP1ABh5jPPY= buf.build/go/bufprivateusage v0.1.0 h1:SzCoCcmzS3zyXHEXHeSQhGI7OTkgtljoknLzsUz9Gg4= diff --git a/make/buf/all.mk b/make/buf/all.mk index 36cc11e426..278dbc057e 100644 --- a/make/buf/all.mk +++ b/make/buf/all.mk @@ -1,7 +1,8 @@ GO_ALL_REPO_PKGS := ./cmd/... ./private/... GO_GET_PKGS := $(GO_GET_PKGS) \ github.com/bufbuild/protocompile@main \ - buf.build/go/standard@main + buf.build/go/standard@main \ + buf.build/go/app@main GO_BINS := $(GO_BINS) \ cmd/buf \ cmd/protoc-gen-buf-breaking \ diff --git a/private/buf/bufcli/completions.go b/private/buf/bufcli/completions.go new file mode 100644 index 0000000000..73b8d887e8 --- /dev/null +++ b/private/buf/bufcli/completions.go @@ -0,0 +1,111 @@ +// Copyright 2020-2026 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bufcli + +import ( + "buf.build/go/standard/xslices" + "github.com/bufbuild/buf/private/buf/bufprint" + "github.com/bufbuild/buf/private/bufpkg/bufanalysis" + "github.com/bufbuild/buf/private/bufpkg/bufconfig" + "github.com/bufbuild/buf/private/bufpkg/bufplugin" + "github.com/spf13/cobra" +) + +// errorFormatDescriptions maps error format strings that have non-obvious names +// to a short description for shell completion. +var errorFormatDescriptions = map[string]string{ + "msvs": "Visual Studio", + "config-ignore-yaml": "buf.yaml ignore_only snippet", +} + +// RegisterFlagCompletionErrorFormat registers shell completion for flags that accept +// a bufanalysis error format value. +func RegisterFlagCompletionErrorFormat(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + xslices.Map(bufanalysis.AllFormatStrings, func(s string) string { + if desc, ok := errorFormatDescriptions[s]; ok { + return cobra.CompletionWithDesc(s, desc) + } + return s + }), + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionLintErrorFormat registers shell completion for flags that accept +// a lint error format value (which includes the extra "config-ignore-yaml" value). +func RegisterFlagCompletionLintErrorFormat(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + xslices.Map(AllLintFormatStrings, func(s string) string { + if desc, ok := errorFormatDescriptions[s]; ok { + return cobra.CompletionWithDesc(s, desc) + } + return s + }), + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionOutputFormat registers shell completion for flags that accept +// a bufprint output format value. +func RegisterFlagCompletionOutputFormat(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + []string{ + bufprint.FormatText.String(), + bufprint.FormatJSON.String(), + }, + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionRuleFormat registers shell completion for flags that accept +// a rule print format value (text or json). +func RegisterFlagCompletionRuleFormat(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + AllRuleFormatStrings, + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionVisibility registers shell completion for flags that accept +// a visibility value. +func RegisterFlagCompletionVisibility(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + allVisibilityStrings, + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionPluginType registers shell completion for flags that accept +// a plugin type value. +func RegisterFlagCompletionPluginType(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + bufplugin.AllPluginTypeStrings, + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +} + +// RegisterFlagCompletionFileVersion registers shell completion for flags that accept +// a bufconfig file version value, ordered with the current recommended version first. +func RegisterFlagCompletionFileVersion(cmd *cobra.Command, flagName string) error { + return cmd.RegisterFlagCompletionFunc(flagName, cobra.FixedCompletions( + []string{ + bufconfig.FileVersionV2.String(), + bufconfig.FileVersionV1.String(), + bufconfig.FileVersionV1Beta1.String(), + }, + cobra.ShellCompDirectiveNoFileComp|cobra.ShellCompDirectiveKeepOrder, + )) +}