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

manifest add --artifact: handle multiple values #5728

Merged
merged 1 commit into from
Sep 11, 2024
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
15 changes: 6 additions & 9 deletions cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,22 @@ func manifestAddCmd(c *cobra.Command, args []string, opts manifestAddOpts) error
switch len(args) {
case 0, 1:
return errors.New("At least a list image and an image or artifact to add must be specified")
case 2:
default:
listImageSpec = args[0]
if listImageSpec == "" {
return fmt.Errorf(`Invalid image name "%s"`, args[0])
return fmt.Errorf("Invalid image name %q", args[0])
}

This comment was marked as outdated.

if opts.artifact {
artifactSpec = args[1:]
} else {
if len(args) > 2 {
return errors.New("Too many arguments: expected list and image add to list")
}
imageSpec = args[1]
if imageSpec == "" {
return fmt.Errorf(`Invalid image name "%s"`, args[1])
return fmt.Errorf("Invalid image name %q", args[1])
}
}
default:
if opts.artifact {
artifactSpec = args[1:]
} else {
return errors.New("Too many arguments: expected list and image add to list")
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been just:

if len(args) < 2 {
  return errors.New("At least a list image and an image or artifact to add must be specified")
}

// the rest of the code - three idents saved


store, err := getStore(c)
Expand Down
8 changes: 8 additions & 0 deletions tests/lists.bats
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ IMAGE_LIST_S390X_INSTANCE_DIGEST=sha256:882a20ee0df7399a445285361d38b711c299ca09
run_buildah manifest rm foo
}

@test "manifest-add-multiple-artifacts" {
run_buildah manifest create foo
createrandom $TEST_SCRATCH_DIR/randomfile4
createrandom $TEST_SCRATCH_DIR/randomfile3
run_buildah manifest add --artifact foo $TEST_SCRATCH_DIR/randomfile3 $TEST_SCRATCH_DIR/randomfile4
run_buildah manifest push --all foo oci:$TEST_SCRATCH_DIR/pushed
}

@test "manifest-add local image" {
target=scratch-image
run_buildah bud $WITH_POLICY_JSON -t ${target} $BUDFILES/from-scratch
Expand Down
Loading