From 1f82c583e3ef0c31cd9d00ba66917592bb18da88 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 28 Oct 2022 22:24:58 +0300 Subject: [PATCH] [#1971] cli: Unify CID and OID flags provision Signed-off-by: Pavel Karpy --- CHANGELOG.md | 3 +++ cmd/neofs-cli/modules/object/lock.go | 31 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbfa7477cf..bc090b3897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ Changelog for NeoFS Node - `morph list-containers` in `neofs-adm` (#1689) ### Changed +- `object lock` command reads CID and OID the same way other commands do (#1971) + ### Fixed - Open FSTree in sync mode by default (#1992) - `neofs-cli container nodes`'s output (#1991) @@ -14,6 +16,7 @@ Changelog for NeoFS Node ### Removed ### Updated ### Updating from v0.34.0 +Pass CID and OID parameters via the `--cid` and `--oid` flags, not as the command arguments. ## [0.34.0] - 2022-10-31 - Marado (마라도, 馬羅島) diff --git a/cmd/neofs-cli/modules/object/lock.go b/cmd/neofs-cli/modules/object/lock.go index 2c76020d0e..9f952d4d19 100644 --- a/cmd/neofs-cli/modules/object/lock.go +++ b/cmd/neofs-cli/modules/object/lock.go @@ -21,22 +21,22 @@ import ( // object lock command. var objectLockCmd = &cobra.Command{ - Use: "lock CONTAINER OBJECT...", + Use: "lock", Short: "Lock object in container", Long: "Lock object in container", - Args: cobra.MinimumNArgs(2), - Run: func(cmd *cobra.Command, args []string) { - var cnr cid.ID + Run: func(cmd *cobra.Command, _ []string) { + cidRaw, _ := cmd.Flags().GetString("cid") - err := cnr.DecodeString(args[0]) + var cnr cid.ID + err := cnr.DecodeString(cidRaw) common.ExitOnErr(cmd, "Incorrect container arg: %v", err) - argsList := args[1:] + oidsRaw, _ := cmd.Flags().GetStringSlice("oid") - lockList := make([]oid.ID, len(argsList)) + lockList := make([]oid.ID, len(oidsRaw)) - for i := range argsList { - err = lockList[i].DecodeString(argsList[i]) + for i := range oidsRaw { + err = lockList[i].DecodeString(oidsRaw[i]) common.ExitOnErr(cmd, fmt.Sprintf("Incorrect object arg #%d: %%v", i+1), err) } @@ -94,7 +94,16 @@ func initCommandObjectLock() { commonflags.Init(objectLockCmd) initFlagSession(objectLockCmd, "PUT") - objectLockCmd.Flags().Uint64P(commonflags.ExpireAt, "e", 0, "Lock expiration epoch") - objectLockCmd.Flags().Uint64(commonflags.Lifetime, 0, "Lock lifetime") + ff := objectLockCmd.Flags() + + ff.String("cid", "", "Container ID") + _ = objectLockCmd.MarkFlagRequired("cid") + + ff.StringSlice("oid", nil, "Object ID") + _ = objectLockCmd.MarkFlagRequired("oid") + + ff.Uint64P(commonflags.ExpireAt, "e", 0, "Lock expiration epoch") + + ff.Uint64(commonflags.Lifetime, 0, "Lock lifetime") objectLockCmd.MarkFlagsMutuallyExclusive(commonflags.ExpireAt, commonflags.Lifetime) }