Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print image list without package yaml when using --image-list flag with inspect #3384

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading