diff --git a/cmd/buf/buf.go b/cmd/buf/buf.go index fdfee55c36..cbd9d5532f 100644 --- a/cmd/buf/buf.go +++ b/cmd/buf/buf.go @@ -126,8 +126,11 @@ import ( "github.com/bufbuild/buf/private/pkg/slogapp" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/spf13/cobra" + "github.com/spf13/pflag" ) +const timeoutFlagName = "timeout" + func main() { appcmd.Main(context.Background(), newRootCommand("buf")) } @@ -135,16 +138,18 @@ func main() { func newRootCommand(name string) *appcmd.Command { builder := appext.NewBuilder( name, - appext.BuilderWithTimeout(120*time.Second), appext.BuilderWithInterceptor(newErrorInterceptor()), appext.BuilderWithLoggerProvider(slogapp.LoggerProvider), ) return &appcmd.Command{ - Use: name, - Short: "The Buf CLI", - Long: "A tool for working with Protocol Buffers and managing resources on the Buf Schema Registry (BSR)", - Version: bufcli.Version, - BindPersistentFlags: builder.BindRoot, + Use: name, + Short: "The Buf CLI", + Long: "A tool for working with Protocol Buffers and managing resources on the Buf Schema Registry (BSR)", + Version: bufcli.Version, + BindPersistentFlags: appcmd.BindMultiple( + builder.BindRoot, + bindHiddenTimeoutFlag, + ), SubCommands: []*appcmd.Command{ build.NewCommand("build", builder), export.NewCommand("export", builder), @@ -623,3 +628,14 @@ func deprecatedMessage(newCommand, oldCommand string) string { newCommand, oldCommand, ) } + +// bindHiddenTimeoutFlag binds a hidden and deprecated timeout flag. +// +// Every command used to have a timeout flag, but we removed this. We need to keep the flag around so that +// callers are not broken. +func bindHiddenTimeoutFlag(flagSet *pflag.FlagSet) { + var timeout time.Duration + flagSet.DurationVar(&timeout, timeoutFlagName, 0, "This flag is deprecated and has no effect.") + _ = flagSet.MarkDeprecated(timeoutFlagName, "this flag has no effect") + _ = flagSet.MarkHidden(timeoutFlagName) +}