Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/build/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/build/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/build/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/build/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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>\", \"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")
Expand Down
7 changes: 4 additions & 3 deletions pkg/cmd/build/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions pkg/cmd/build/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion pkg/cmd/build/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")

Expand Down