Skip to content

Commit

Permalink
cli: allow multiple --oid objects in delete command
Browse files Browse the repository at this point in the history
Closes #2774.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Jun 26, 2024
1 parent 40fa31d commit a342dde
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog for NeoFS Node
### Fixed

### Changed
- neofs-cli allows several objects deletion at a time (#2774)

### Removed

Expand Down
54 changes: 34 additions & 20 deletions cmd/neofs-cli/modules/object/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,67 @@ func initObjectDeleteCmd() {
flags := objectDelCmd.Flags()

flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
flags.String(commonflags.OIDFlag, "", commonflags.OIDFlagUsage)
flags.StringSlice(commonflags.OIDFlag, nil, commonflags.OIDFlagUsage)

Check warning on line 31 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L31

Added line #L31 was not covered by tests
flags.Bool(binaryFlag, false, "Deserialize object structure from given file.")
flags.String(fileFlag, "", "File with object payload")

_ = objectDelCmd.MarkFlagRequired(commonflags.CIDFlag)
_ = objectDelCmd.MarkFlagRequired(commonflags.OIDFlag)

Check warning on line 36 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

func deleteObject(cmd *cobra.Command, _ []string) {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

var cnr cid.ID
var obj oid.ID
var objAddr oid.Address
var objs []oid.ID
var objAddrs []oid.Address

Check warning on line 45 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L44-L45

Added lines #L44 - L45 were not covered by tests

binary, _ := cmd.Flags().GetBool(binaryFlag)
if binary {
filename, _ := cmd.Flags().GetString(fileFlag)
if filename == "" {
common.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", fileFlag))
}
objAddr = readObjectAddressBin(cmd, &cnr, &obj, filename)
var obj oid.ID
objAddr := readObjectAddressBin(cmd, &cnr, &obj, filename)

Check warning on line 54 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L53-L54

Added lines #L53 - L54 were not covered by tests

objs = []oid.ID{obj}
objAddrs = []oid.Address{objAddr}

Check warning on line 57 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L56-L57

Added lines #L56 - L57 were not covered by tests
} else {
cidVal, _ := cmd.Flags().GetString(commonflags.CIDFlag)
if cidVal == "" {
common.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", commonflags.CIDFlag))
}
readCID(cmd, &cnr)
oIDVals, _ := cmd.Flags().GetStringSlice(commonflags.OIDFlag)

Check warning on line 60 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L59-L60

Added lines #L59 - L60 were not covered by tests

oidVal, _ := cmd.Flags().GetString(commonflags.OIDFlag)
if oidVal == "" {
common.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", commonflags.OIDFlag))
}
var obj oid.ID
var objAddr oid.Address
objAddr.SetContainer(cnr)

Check warning on line 64 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L62-L64

Added lines #L62 - L64 were not covered by tests

objAddr = readObjectAddress(cmd, &cnr, &obj)
for _, oIDraw := range oIDVals {
err := obj.DecodeString(oIDraw)
common.ExitOnErr(cmd, "decode object ID string: %w", err)

Check warning on line 68 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L66-L68

Added lines #L66 - L68 were not covered by tests

objAddr.SetObject(obj)
objs = append(objs, obj)
objAddrs = append(objAddrs, objAddr)

Check warning on line 72 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L70-L72

Added lines #L70 - L72 were not covered by tests
}
}

pk := key.GetOrGenerate(cmd)

var prm internalclient.DeleteObjectPrm
ReadOrOpenSession(ctx, cmd, &prm, pk, cnr, obj)
ReadOrOpenSession(ctx, cmd, &prm, pk, cnr, objs...)

Check warning on line 79 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L79

Added line #L79 was not covered by tests
Prepare(cmd, &prm)
prm.SetPrivateKey(*pk)
prm.SetAddress(objAddr)

res, err := internalclient.DeleteObject(ctx, prm)
common.ExitOnErr(cmd, "rpc error: %w", err)
for _, addr := range objAddrs {
prm.SetAddress(addr)

Check warning on line 84 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L83-L84

Added lines #L83 - L84 were not covered by tests

tomb := res.Tombstone()
res, err := internalclient.DeleteObject(ctx, prm)
common.ExitOnErr(cmd, "rpc error: %w", err)

Check warning on line 87 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L86-L87

Added lines #L86 - L87 were not covered by tests

cmd.Println("Object removed successfully.")
cmd.Printf(" ID: %s\n CID: %s\n", tomb, cnr)
tomb := res.Tombstone()

Check warning on line 89 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L89

Added line #L89 was not covered by tests

cmd.Printf("Object %s removed successfully.", addr)
cmd.Printf(" ID: %s\n CID: %s\n", tomb, cnr)

Check warning on line 92 in cmd/neofs-cli/modules/object/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/object/delete.go#L91-L92

Added lines #L91 - L92 were not covered by tests
}
}

0 comments on commit a342dde

Please sign in to comment.