Skip to content

Commit

Permalink
fix(cli): fix pipeline show with attached applications (#1024)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj authored and yesnault committed Sep 5, 2017
1 parent a2bdb5b commit a048d81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
19 changes: 16 additions & 3 deletions cli/cds/pipeline/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/ovh/cds/sdk"
)

var withApplications bool

func pipelineShowCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Expand All @@ -17,19 +19,30 @@ func pipelineShowCmd() *cobra.Command {
Aliases: []string{"describe"},
Run: showPipeline,
}

cmd.Flags().BoolVarP(&withApplications, "withApplications", "", false, "Show linked applications")

return cmd
}

func showPipeline(cmd *cobra.Command, args []string) {
var p *sdk.Pipeline
var errG error
if len(args) != 2 {
sdk.Exit("Wrong usage: see %s\n", cmd.Short)
}

projectKey := args[0]
pipelineName := args[1]
p, err := sdk.GetPipeline(projectKey, pipelineName)
if err != nil {
sdk.Exit("Error: cannot retrieve pipeline informations: %s\n", err)

if withApplications {
p, errG = sdk.GetPipeline(projectKey, pipelineName, sdk.GetPipelineOptions.WithApplications)
} else {
p, errG = sdk.GetPipeline(projectKey, pipelineName)
}

if errG != nil {
sdk.Exit("Error: cannot retrieve pipeline informations: %s\n", errG)
}

data, err := yaml.Marshal(p)
Expand Down
15 changes: 13 additions & 2 deletions sdk/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ type RunRequest struct {
ParentApplicationID int64 `json:"parent_application_id,omitempty"`
}

// GetPipelineOptions are options for GetPipeline
var GetPipelineOptions = struct {
WithApplications RequestModifier
}{
WithApplications: func(r *http.Request) {
q := r.URL.Query()
q.Set("withApplications", "true")
r.URL.RawQuery = q.Encode()
},
}

// ListPipelines retrieves all available pipelines to called
func ListPipelines(projectKey string) ([]Pipeline, error) {
url := fmt.Sprintf("/project/%s/pipeline", projectKey)
Expand All @@ -161,9 +172,9 @@ func ListPipelines(projectKey string) ([]Pipeline, error) {
}

// GetPipeline retrieves pipeline definition from CDS
func GetPipeline(key, name string) (*Pipeline, error) {
func GetPipeline(key, name string, opts ...RequestModifier) (*Pipeline, error) {
path := fmt.Sprintf("/project/%s/pipeline/%s", key, name)
data, _, errr := Request("GET", path, nil)
data, _, errr := Request("GET", path, nil, opts...)
if errr != nil {
return nil, errr
}
Expand Down

0 comments on commit a048d81

Please sign in to comment.