From a10e196b3f9724c4cd7f912970e1e4777f5ab8c6 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Wed, 8 Jan 2025 07:25:20 -0500 Subject: [PATCH] fix: print image list without package yaml when using `--image-list` flag with inspect (#3384) Signed-off-by: Austin Abro --- src/cmd/package.go | 6 ++++++ src/internal/packager2/inspect.go | 19 +++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index bac5d45d48..f927acc4b2 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -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 { @@ -401,6 +406,7 @@ func (o *PackageInspectOptions) Run(cmd *cobra.Command, args []string) error { return err } } + return nil } output, err := packager2.Inspect(ctx, inspectOpt) diff --git a/src/internal/packager2/inspect.go b/src/internal/packager2/inspect.go index ca03d51f4c..d6c952474f 100644 --- a/src/internal/packager2/inspect.go +++ b/src/internal/packager2/inspect.go @@ -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) {