diff --git a/pkg/cmd/build/build.go b/pkg/cmd/build/build.go index 5e539a49..79ee4a45 100644 --- a/pkg/cmd/build/build.go +++ b/pkg/cmd/build/build.go @@ -27,6 +27,8 @@ func NewCmdBuild(f *factory.Factory) *cobra.Command { }, } + cmd.PersistentFlags().StringP("pipeline", "p", "", "The pipeline to use. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.") + cmd.AddCommand(NewCmdBuildCancel(f)) cmd.AddCommand(NewCmdBuildDownload(f)) cmd.AddCommand(NewCmdBuildList(f)) diff --git a/pkg/cmd/build/cancel.go b/pkg/cmd/build/cancel.go index 7a14c6b5..624aa834 100644 --- a/pkg/cmd/build/cancel.go +++ b/pkg/cmd/build/cancel.go @@ -46,6 +46,9 @@ func NewCmdBuildCancel(f *factory.Factory) *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Get pipeline from persistent flag + pipeline, _ = cmd.Flags().GetString("pipeline") + pipelineRes := pipelineResolver.NewAggregateResolver( pipelineResolver.ResolveFromFlag(pipeline, f.Config), pipelineResolver.ResolveFromConfig(f.Config, pipelineResolver.PickOne), @@ -79,9 +82,7 @@ func NewCmdBuildCancel(f *factory.Factory) *cobra.Command { } cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the build in a web browser after it has been cancelled.") - cmd.Flags().StringVarP(&pipeline, "pipeline", "p", "", "The pipeline to cancel a build on. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+ - "If omitted, it will be resolved using the current directory.", - ) + // Pipeline flag now inherited from parent command cmd.Flags().BoolVarP(&confirmed, "yes", "y", false, "Skip the confirmation prompt. Useful if being used in automation/CI.") cmd.Flags().SortFlags = false diff --git a/pkg/cmd/build/download.go b/pkg/cmd/build/download.go index 2ab90b49..650316e2 100644 --- a/pkg/cmd/build/download.go +++ b/pkg/cmd/build/download.go @@ -45,6 +45,9 @@ func NewCmdBuildDownload(f *factory.Factory) *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Get pipeline from persistent flag + pipeline, _ = cmd.Flags().GetString("pipeline") + // we find the pipeline based on the following rules: // 1. an explicit flag is passed // 2. a configured pipeline for this directory @@ -105,9 +108,7 @@ func NewCmdBuildDownload(f *factory.Factory) *cobra.Command { cmd.Flags().BoolVarP(&mine, "mine", "m", false, "Filter builds to only my user.") cmd.Flags().StringVarP(&branch, "branch", "b", "", "Filter builds to this branch.") cmd.Flags().StringVarP(&user, "user", "u", "", "Filter builds to this user. You can use name or email.") - cmd.Flags().StringVarP(&pipeline, "pipeline", "p", "", "The pipeline to view. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+ - "If omitted, it will be resolved using the current directory.", - ) + // Pipeline flag now inherited from parent command // can only supply --user or --mine cmd.MarkFlagsMutuallyExclusive("mine", "user") cmd.Flags().SortFlags = false diff --git a/pkg/cmd/build/list.go b/pkg/cmd/build/list.go index d64af820..dc766708 100644 --- a/pkg/cmd/build/list.go +++ b/pkg/cmd/build/list.go @@ -109,6 +109,9 @@ func NewCmdBuildList(f *factory.Factory) *cobra.Command { return err } + // Get pipeline from persistent flag + opts.pipeline, _ = cmd.Flags().GetString("pipeline") + if opts.limit > maxBuildLimit { return fmt.Errorf("limit cannot exceed %d builds (requested: %d)", maxBuildLimit, opts.limit) } @@ -148,7 +151,7 @@ func NewCmdBuildList(f *factory.Factory) *cobra.Command { "requiredScopes": string(scopes.ReadBuilds), } - cmd.Flags().StringVarP(&opts.pipeline, "pipeline", "p", "", "Filter by pipeline slug") + // Pipeline flag now inherited from parent command cmd.Flags().StringVar(&opts.since, "since", "", "Filter builds created since this time (e.g. 1h, 30m)") cmd.Flags().StringVar(&opts.until, "until", "", "Filter builds created before this time (e.g. 1h, 30m)") cmd.Flags().StringVar(&opts.duration, "duration", "", "Filter by duration (e.g. >5m, <10m, 20m) - supports >, <, >=, <= operators") diff --git a/pkg/cmd/build/new.go b/pkg/cmd/build/new.go index a0eb15c9..0c1c1b8c 100644 --- a/pkg/cmd/build/new.go +++ b/pkg/cmd/build/new.go @@ -80,6 +80,9 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command { return nil }), RunE: bkErrors.WrapRunE(func(cmd *cobra.Command, args []string) error { + // Get pipeline from persistent flag + pipeline, _ = cmd.Flags().GetString("pipeline") + resolvers := resolver.NewAggregateResolver( resolver.ResolveFromFlag(pipeline, f.Config), resolver.ResolveFromConfig(f.Config, resolver.PickOne), @@ -162,9 +165,7 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command { cmd.Flags().StringVarP(&branch, "branch", "b", "", "The branch to build. Defaults to the default branch of the pipeline.") cmd.Flags().StringVarP(&author, "author", "a", "", "Author of the build. Supports: \"Name \", \"email@domain.com\", \"Full Name\", or \"username\"") cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the build in a web browser after it has been created.") - cmd.Flags().StringVarP(&pipeline, "pipeline", "p", "", "The pipeline to build. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+ - "If omitted, it will be resolved using the current directory.", - ) + // Pipeline flag now inherited from parent command cmd.Flags().StringArrayVarP(&env, "env", "e", []string{}, "Set environment variables for the build") cmd.Flags().StringArrayVarP(&metaData, "metadata", "M", []string{}, "Set metadata for the build (KEY=VALUE)") cmd.Flags().BoolVarP(&ignoreBranchFilters, "ignore-branch-filters", "i", false, "Ignore branch filters for the pipeline") diff --git a/pkg/cmd/build/rebuild.go b/pkg/cmd/build/rebuild.go index 2d92e490..49e0a638 100644 --- a/pkg/cmd/build/rebuild.go +++ b/pkg/cmd/build/rebuild.go @@ -47,6 +47,9 @@ func NewCmdBuildRebuild(f *factory.Factory) *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { + // Get pipeline from persistent flag + pipeline, _ = cmd.Flags().GetString("pipeline") + // we find the pipeline based on the following rules: // 1. an explicit flag is passed // 2. a configured pipeline for this directory @@ -98,9 +101,7 @@ func NewCmdBuildRebuild(f *factory.Factory) *cobra.Command { cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the build in a web browser after it has been created.") cmd.Flags().StringVarP(&branch, "branch", "b", "", "Filter builds to this branch.") cmd.Flags().StringVarP(&user, "user", "u", "", "Filter builds to this user. You can use name or email.") - cmd.Flags().StringVarP(&pipeline, "pipeline", "p", "", "The pipeline to build. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+ - "If omitted, it will be resolved using the current directory.", - ) + // Pipeline flag now inherited from parent command // can only supply --user or --mine cmd.MarkFlagsMutuallyExclusive("mine", "user") cmd.Flags().SortFlags = false diff --git a/pkg/cmd/build/view.go b/pkg/cmd/build/view.go index 2f0163b7..3bab89d5 100644 --- a/pkg/cmd/build/view.go +++ b/pkg/cmd/build/view.go @@ -57,6 +57,9 @@ func NewCmdBuildView(f *factory.Factory) *cobra.Command { return err } + // Get pipeline from persistent flag + opts.Pipeline, _ = cmd.Flags().GetString("pipeline") + // Resolve pipeline first pipelineRes := pipelineResolver.NewAggregateResolver( pipelineResolver.ResolveFromFlag(opts.Pipeline, f.Config), @@ -185,15 +188,11 @@ func NewCmdBuildView(f *factory.Factory) *cobra.Command { cmd.Flags().BoolVar(&opts.Web, "web", false, "Open the build in a web browser.") cmd.Flags().StringVar(&branch, "branch", "", "Filter builds to this branch.") cmd.Flags().StringVar(&user, "user", "", "Filter builds to this user. You can use name or email.") - cmd.Flags().StringVar(&opts.Pipeline, "pipeline", "", "The pipeline to view. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+ - "If omitted, it will be resolved using the current directory.", - ) // can only supply --user or --mine - cmd.MarkFlagsMutuallyExclusive("mine", "user") - cmd.Flags().SortFlags = false + cmd.MarkFlagsMutuallyExclusive("user", "mine") output.AddFlags(cmd.Flags()) - + cmd.Flags().SortFlags = false return cmd } diff --git a/pkg/cmd/build/watch.go b/pkg/cmd/build/watch.go index 3439c4fe..aa9ccaa3 100644 --- a/pkg/cmd/build/watch.go +++ b/pkg/cmd/build/watch.go @@ -75,6 +75,9 @@ func NewCmdBuildWatch(f *factory.Factory) *cobra.Command { return scopes.ValidateCommandScopes(cmd, f.Config.GetTokenScopes()) }, RunE: func(cmd *cobra.Command, args []string) error { + // Get pipeline from persistent flag + opts.Pipeline, _ = cmd.Flags().GetString("pipeline") + pipelineRes := pipelineResolver.NewAggregateResolver( pipelineResolver.ResolveFromFlag(opts.Pipeline, f.Config), pipelineResolver.ResolveFromConfig(f.Config, pipelineResolver.PickOne), @@ -129,7 +132,7 @@ func NewCmdBuildWatch(f *factory.Factory) *cobra.Command { "requiredScopes": string(scopes.ReadBuilds), } - cmd.Flags().StringVarP(&opts.Pipeline, "pipeline", "p", "", "The pipeline to watch. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.") + // Pipeline flag now inherited from parent command cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "The branch to watch builds for.") cmd.Flags().IntVar(&opts.IntervalSeconds, "interval", opts.IntervalSeconds, "Polling interval in seconds")