Skip to content

Commit

Permalink
fix: print image list without package yaml when using --image-list
Browse files Browse the repository at this point in the history
…flag with inspect (#3384)

Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 authored Jan 8, 2025
1 parent 56f62ea commit a10e196
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ func (o *PackageInspectOptions) PreRun(_ *cobra.Command, _ []string) {
// Run performs the execution of 'package inspect' sub-command.
func (o *PackageInspectOptions) Run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

if pkgConfig.InspectOpts.ListImages && (pkgConfig.InspectOpts.SBOMOutputDir != "" || pkgConfig.InspectOpts.ViewSBOM) {
return fmt.Errorf("cannot use --sbom or --sbom-out and --list-images at the same time")
}

// NOTE(mkcp): Gets user input with message
src, err := choosePackage(ctx, args)
if err != nil {
Expand Down Expand Up @@ -401,6 +406,7 @@ func (o *PackageInspectOptions) Run(cmd *cobra.Command, args []string) error {
return err
}
}
return nil
}

output, err := packager2.Inspect(ctx, inspectOpt)
Expand Down
19 changes: 7 additions & 12 deletions src/internal/packager2/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,14 @@ func InspectList(ctx context.Context, opt ZarfInspectOptions) ([]string, error)
if err != nil {
return nil, err
}
// Only list images if we have components
if len(pkg.Components) > 0 {
for _, component := range pkg.Components {
imageList = append(imageList, component.Images...)
}
if len(imageList) > 0 {
imageList = helpers.Unique(imageList)
return imageList, nil
}
return nil, fmt.Errorf("failed listing images: list of images found in components: %d", len(imageList))
for _, component := range pkg.Components {
imageList = append(imageList, component.Images...)
}

return imageList, err
if imageList == nil {
return nil, fmt.Errorf("failed listing images: 0 images found in package")
}
imageList = helpers.Unique(imageList)
return imageList, nil
}

func getPackageMetadata(ctx context.Context, opt ZarfInspectOptions) (v1alpha1.ZarfPackage, error) {
Expand Down

0 comments on commit a10e196

Please sign in to comment.