Skip to content

Commit 83cf194

Browse files
feat(image): list all (#1356)
* feat(image): list all Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud> * examples Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud> * print scope and owner Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud> * docs Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud> --------- Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud> Co-authored-by: cgoetz-inovex <carlo.goetz@inovex.de>
1 parent 29a5cc3 commit 83cf194

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

docs/stackit_image_list.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ stackit image list [flags]
1313
### Examples
1414

1515
```
16-
List all images
16+
List images in your project
1717
$ stackit image list
1818
1919
List images with label
2020
$ stackit image list --label-selector ARM64,dev
2121
2222
List the first 10 images
2323
$ stackit image list --limit=10
24+
25+
List all images
26+
$ stackit image list --all
2427
```
2528

2629
### Options
2730

2831
```
32+
--all List all images available
2933
-h, --help Help for "stackit image list"
3034
--label-selector string Filter by label
3135
--limit int Limit the output to the first n elements

internal/cmd/image/list/list.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ type inputModel struct {
2525
*globalflags.GlobalFlagModel
2626
LabelSelector *string
2727
Limit *int64
28+
All *bool
2829
}
2930

3031
const (
3132
labelSelectorFlag = "label-selector"
3233
limitFlag = "limit"
34+
allFlag = "all"
3335
)
3436

3537
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -40,7 +42,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
4042
Args: args.NoArgs,
4143
Example: examples.Build(
4244
examples.NewExample(
43-
`List all images`,
45+
`List images in your project`,
4446
`$ stackit image list`,
4547
),
4648
examples.NewExample(
@@ -51,6 +53,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
5153
`List the first 10 images`,
5254
`$ stackit image list --limit=10`,
5355
),
56+
examples.NewExample(
57+
`List all images`,
58+
`$ stackit image list --all`,
59+
),
5460
),
5561
RunE: func(cmd *cobra.Command, args []string) error {
5662
ctx := context.Background()
@@ -103,6 +109,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
103109
func configureFlags(cmd *cobra.Command) {
104110
cmd.Flags().String(labelSelectorFlag, "", "Filter by label")
105111
cmd.Flags().Int64(limitFlag, 0, "Limit the output to the first n elements")
112+
cmd.Flags().Bool(allFlag, false, "List all images available")
106113
}
107114

108115
func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
@@ -123,6 +130,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
123130
GlobalFlagModel: globalFlags,
124131
LabelSelector: flags.FlagToStringPointer(p, cmd, labelSelectorFlag),
125132
Limit: limit,
133+
All: flags.FlagToBoolPointer(p, cmd, allFlag),
126134
}
127135

128136
p.DebugInputModel(model)
@@ -134,20 +142,26 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
134142
if model.LabelSelector != nil {
135143
request = request.LabelSelector(*model.LabelSelector)
136144
}
145+
if model.All != nil {
146+
request = request.All(*model.All)
147+
}
137148

138149
return request
139150
}
151+
140152
func outputResult(p *print.Printer, outputFormat string, items []iaas.Image) error {
141153
return p.OutputResult(outputFormat, items, func() error {
142154
table := tables.NewTable()
143-
table.SetHeader("ID", "NAME", "OS", "ARCHITECTURE", "DISTRIBUTION", "VERSION", "LABELS")
155+
table.SetHeader("ID", "NAME", "OS", "ARCHITECTURE", "DISTRIBUTION", "VERSION", "SCOPE", "OWNER", "LABELS")
144156
for i := range items {
145157
item := items[i]
146158
var (
147159
architecture = "n/a"
148160
os = "n/a"
149161
distro = "n/a"
150162
version = "n/a"
163+
owner = "n/a"
164+
scope = "n/a"
151165
)
152166
if cfg := item.Config; cfg != nil {
153167
if v := cfg.Architecture; v != nil {
@@ -163,12 +177,21 @@ func outputResult(p *print.Printer, outputFormat string, items []iaas.Image) err
163177
version = *v.Get()
164178
}
165179
}
180+
if v := item.GetOwner(); v != "" {
181+
owner = v
182+
}
183+
if v := item.GetScope(); v != "" {
184+
scope = v
185+
}
186+
166187
table.AddRow(utils.PtrString(item.Id),
167188
utils.PtrString(item.Name),
168189
os,
169190
architecture,
170191
distro,
171192
version,
193+
scope,
194+
owner,
172195
utils.JoinStringKeysPtr(*item.Labels, ","))
173196
}
174197
err := table.Display(p)

0 commit comments

Comments
 (0)