Skip to content

Commit

Permalink
Add ability to list modules on stack show
Browse files Browse the repository at this point in the history
Updated the stack show command to allow modules to be listed now that the API has been updated to allow the owner to be shown.

Issues: #41
  • Loading branch information
adamconnelly committed Nov 19, 2021
1 parent dfa6d4d commit 427d76d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions internal/cmd/stack/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ type showStackQuery struct {
ID string `graphql:"id" json:"id,omitempty"`
Number string `graphql:"number" json:"number,omitempty"`
Module struct {
ID string `graphql:"id" json:"id,omitempty"`
Name string `graphql:"name" json:"name,omitempty"`
ID string `graphql:"id" json:"id,omitempty"`
Name string `graphql:"name" json:"name,omitempty"`
Owner string `graphql:"owner" json:"owner,omitempty"`
} `graphql:"module" json:"module"`
} `graphql:"moduleVersionsUsed" json:"moduleVersionsUsed,omitempty"`
Name string `graphql:"name" json:"name,omitempty"`
Expand Down Expand Up @@ -163,6 +164,9 @@ func (c *showStackCommand) showStackTable(query showStackQuery) error {
if err := c.outputPolicies(query); err != nil {
return err
}
if err := c.outputModuleVersionUsage(query); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -336,6 +340,31 @@ func (c *showStackCommand) outputScripts(scripts []string, title string) error {
return nil
}

func (c *showStackCommand) outputModuleVersionUsage(query showStackQuery) error {
if len(query.Stack.ModuleVersionsUsed) == 0 {
return nil
}

sort.SliceStable(query.Stack.ModuleVersionsUsed, func(i, j int) bool {
a := query.Stack.ModuleVersionsUsed[i]
b := query.Stack.ModuleVersionsUsed[j]

return a.Module.Owner < b.Module.Owner || (a.Module.Owner == b.Module.Owner && a.Module.Name < b.Module.Name)
})

pterm.DefaultSection.WithLevel(2).Println("Modules Used")
tableData := [][]string{{"Owner", "Name", "Version"}}
for _, version := range query.Stack.ModuleVersionsUsed {
tableData = append(tableData, []string{
version.Module.Owner,
version.Module.Name,
version.Number,
})
}

return cmd.OutputTable(tableData, true)
}

func (c *showStackCommand) humanizeVendor(vendorConfigType string) string {
switch vendorConfigType {
case stackConfigVendorPulumi:
Expand Down

0 comments on commit 427d76d

Please sign in to comment.