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

cli: Improve UX concerning attributes' setting in object put command #2427

Closed
cthulhu-rider opened this issue Jul 7, 2023 · 1 comment · Fixed by #2569
Closed

cli: Improve UX concerning attributes' setting in object put command #2427

cthulhu-rider opened this issue Jul 7, 2023 · 1 comment · Fixed by #2569
Assignees
Labels
neofs-cli NeoFS CLI application issues
Milestone

Comments

@cthulhu-rider
Copy link
Contributor

cthulhu-rider commented Jul 7, 2023

Context

Originally posted by @vvarg229

$  neofs-cli object put <required_flags> --attributes RunNumber=184 --attributes FilePath=184.zip ContentType=application/zip

command executed successfully. Resulting object was created with FilePath attribute and without ContentType and Number ones.

Overview

currently object put command accepts single flag attributes of string type to specify list of user-defined object attributes:

$ neofs-cli object put -h
      --attributes string     User attributes in form of Key1=Value1,Key2=Value2

with next behavior:

  • if multiple flags specified (see example), only the latest one will enter the object
  • if value contains spaces, all data starting from the 1st space is ignored

Proposal

1. Change type to repeated strings

it may be incovenient to specify multiple attributes in single comma-separated flag without spaces (imagine 5+ elements).

we can support the ability to repeat the flag, while still maintaining the comma-separated format. It'll be easy todo via Cobra's (NeoFS CLI engine) https://pkg.go.dev/github.com/spf13/pflag#StringSlice flag type. In example above, user could specify

--attributes RunNumber=184,FilePath=184.zip --attributes ContentType=application/zip

and all 3 attributes would be accepted. It may be useful when, for example, some attributes are related like RunNumber and FilePath while ContentType is still independent.

as an alternative, we can support multiple flags with single attributes (w/o comma-splitting within single value). To do this, Cobra provides https://pkg.go.dev/github.com/spf13/pflag#StringArray flag type.

--attribute RunNumber=184 --attribute FilePath=184.zip --attribute ContentType=application/zip

With this approach, the name --attributes becomes redundant and can be replaced by --attribute. To me, this alternative a bit weaker then the slice one, but also concise.

2. Strict positional arguments

as we can see in the original example, space-separated ContentType=application/zip input is ignored. It happens cuz Cobra interprets this input part as one of the command's positional arguments, and object put command just ignores them. From the user pov, it happens unexpectedly and the input quietly disappears inside.

as a solution, we can start to strictly verify positional input of the command (worth to do for all commands globally), so user could see invalid input message and write his command more precisely.

imo strictness is always much better than freedom bordering on uncertainty

AFAIK, similar improvement were added in NeoGo project, correct me pls @AnnaShaleva @roman-khimov

@roman-khimov
Copy link
Member

--attribute seems to be the right way for this particular problem.

Positional arguments check is a different issue (#2494), but it needs to be resolved as well, yes.

@roman-khimov roman-khimov added this to the v0.39.0 milestone Aug 10, 2023
AliceInHunterland added a commit that referenced this issue Sep 12, 2023
The `object put` command previously could only retrieve the last
`--attributes` parameter if multiple such parameters were provided. Now,
 the `object put` command correctly parses all `--attributes` values,
 whether they are provided as comma-separated or single values.

Closes #2427.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
AliceInHunterland added a commit that referenced this issue Sep 12, 2023
The `object put` command previously could only retrieve the last
`--attributes` parameter if multiple such parameters were provided. Now,
 the `object put` command correctly parses all `--attributes` values,
 whether they are provided as comma-separated or single values.

Closes #2427.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
@roman-khimov roman-khimov modified the milestones: v0.39.0, v0.38.0 Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
neofs-cli NeoFS CLI application issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants