Skip to content

Commit

Permalink
fly: add --team option to get-pipeline command
Browse files Browse the repository at this point in the history
Allows fly cli to get pipeline for different teams
without having to switch targets

concourse#5215

Signed-off-by: techgaun <[email protected]>
  • Loading branch information
techgaun committed Oct 9, 2020
1 parent 11e614d commit 223b331
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion fly/commands/get_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
"github.com/concourse/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/concourse/fly/rc"
"github.com/concourse/concourse/fly/ui"
"github.com/concourse/concourse/go-concourse/concourse"
"github.com/mattn/go-isatty"
)

type GetPipelineCommand struct {
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Get configuration of this pipeline"`
JSON bool `short:"j" long:"json" description:"Print config as json instead of yaml"`
Team string `long:"team" description:"Name of the team to which the pipeline belongs, if different from the target default"`
}

func (command *GetPipelineCommand) Validate() error {
Expand All @@ -42,7 +44,18 @@ func (command *GetPipelineCommand) Execute(args []string) error {
return err
}

config, _, found, err := target.Team().PipelineConfig(command.Pipeline.Ref())
var team concourse.Team

if command.Team != "" {
team, err = target.FindTeam(command.Team)
if err != nil {
return err
}
} else {
team = target.Team()
}

config, _, found, err := team.PipelineConfig(command.Pipeline.Ref())
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions fly/integration/error_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ var _ = Describe("Fly CLI", func() {
exec.Command(flyPath, "-t", targetName, "set-pipeline", "-p", "pipeline", "-c", "fixtures/testConfig.yml", "--team", "doesnotexist")),
Entry("destroy-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "destroy-pipeline", "-p", "pipeline", "--team", "doesnotexist")),
Entry("get-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "get-pipeline", "-p", "pipeline", "--team", "doesnotexist")),
)

DescribeTable("and you are NOT authorized to view the team",
Expand Down Expand Up @@ -160,6 +162,8 @@ var _ = Describe("Fly CLI", func() {
exec.Command(flyPath, "-t", targetName, "set-pipeline", "-p", "pipeline", "-c", "fixtures/testConfig.yml", "--team", "other-team")),
Entry("destroy-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "destroy-pipeline", "-p", "pipeline", "--team", "other-team")),
Entry("get-pipeline command returns an error",
exec.Command(flyPath, "-t", targetName, "get-pipeline", "-p", "pipeline", "--team", "other-team")),
)
})
})

0 comments on commit 223b331

Please sign in to comment.