cli: Use array type for parameters to object
subcommands #1615
Labels
No labels
P0
P1
P2
P3
badger
frostfs-adm
frostfs-cli
frostfs-ir
frostfs-lens
frostfs-node
good first issue
triage
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#1615
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "elebedeva/frostfs-node:fix/array-for-range"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #1570
Changed flag type:
--range
inobject hash
andobject range
,--attributes
inobject put
and--new-attrs
inobject patch
fromString
toStringSlice
so that they could take comma-separated values as arguments and split them accordingly.Signed-off-by: Ekaterina Lebedeva ekaterina.lebedeva@yadro.com
cli: Use array type forto cli: Use array type for parameters to--range
parameter toobject hash
object
subcommands@ -196,4 +196,2 @@
func getRangeList(cmd *cobra.Command) ([]objectSDK.Range, error) {
v := cmd.Flag("range").Value.String()
if len(v) == 0 {
Why do we handle the error this way? This error could indicate other issues, e.g., the flag type might not be a string slice. I’d expect the following
This code works as expected because (I hope this will be clear)
len(vs) == 0
-->err == nil
orerr != nil
len(vs) != 0
-->err == nil
But in my opinion, it could be confusing for a reader
I think each possible argument may be used as a string slice (needs do be checked).
So the only error here is when the flag is missing or has the wrong type (all these errors may be statically checked)
It seems to be true.
As @fyrchik said, only possible error types here are either flag is missing or it has the wrong type. Both are problems caused by wrong initialization of the flag. Both are not related to the function logic. So IMO explicitly checking an error is more confusing here.
What's the function logic in this case? Return some library error if the array is empty? It looks strange for me
Why not just return an error if there's an error? What's confusing?
That's exactly what happens here
To explicitly check an error that is related to flag initialization and not to the value of parameter we got, as you suggested. We try to get a slice of passed parameters -> it is empty -> we return nil and any possible error. That's how I see it.
If you still think it's necessary, will change like this do?
I don't suggest to check the error, just return it
I still don't get why do you want to do this check separately.
Because
if len(vs) == 0 || err != nil
seems idiomatic to me, we have used it multiple times.OK, fixed.
7bdec4632b
to76b6ffaf7c
New commits pushed, approval review dismissed automatically according to repository settings
76b6ffaf7c
toa788d44773
vulncheck failed