Skip to content

Commit

Permalink
introduce show-usage for image ls (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Dec 3, 2021
1 parent 5027ea3 commit 102ecc2
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 41 deletions.
13 changes: 12 additions & 1 deletion cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newImageCmd(c *config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return c.imageList()
},
PreRun: bindPFlags,
}
imageDescribeCmd := &cobra.Command{
Use: "describe <imageID>",
Expand Down Expand Up @@ -109,6 +110,8 @@ Example:
# metalctl image apply -f ubuntu.yaml`)
must(imageApplyCmd.MarkFlagRequired("file"))

imageListCmd.Flags().Bool("show-usage", false, "show from how many allocated machines every image is used")

imageCmd.AddCommand(imageListCmd)
imageCmd.AddCommand(imageDescribeCmd)
imageCmd.AddCommand(imageCreateCmd)
Expand All @@ -121,7 +124,15 @@ Example:
}

func (c *config) imageList() error {
resp, err := c.driver.ImageList()
var (
resp *metalgo.ImageListResponse
err error
)
if viper.GetBool("show-usage") {
resp, err = c.driver.ImageListWithUsage()
} else {
resp, err = c.driver.ImageList()
}
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ go 1.16

require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.12.0
github.com/fatih/color v1.13.0
github.com/metal-stack/masterdata-api v0.8.8
github.com/metal-stack/metal-go v0.15.6
github.com/metal-stack/metal-lib v0.8.0
github.com/metal-stack/metal-go v0.16.1
github.com/metal-stack/metal-lib v0.8.1
github.com/metal-stack/updater v1.1.3
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
Loading

0 comments on commit 102ecc2

Please sign in to comment.