You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
https://pkg.go.dev/github.com/spf13/cobra is a std engine for NeoFS command line tools. Some commands accept declare flag(s) of slice/array type. They are passed as --flag XXX --flag XXX .... Then Cobra parses them into Go []T where exact T varies, e.g. StringSlice
there is one feature (???) of parsing such flags: a missing optional flag is treated the same as an explicitly specified with empty values:
note that if --flag is marked required, then 1st command will Error: required flag(s) "oid" not set while 2nd is still parsed as an empty slice
this not very obvious behavior can make the execution of some commands quite unexpected. For example, when command does useful actions in for loop
Expected Behavior
when command accepts slice flag and parses each element which must not be an empty string (like container/object/user IDs), passing --flag "" leads to zero-len failure
Current Behavior
if command checks flag len explicitly - fail, otherwise empty element just lost, and command may become even no-op
https://pkg.go.dev/github.com/spf13/cobra is a std engine for NeoFS command line tools. Some commands accept declare flag(s) of slice/array type. They are passed as
--flag XXX --flag XXX ...
. Then Cobra parses them into Go[]T
where exactT
varies, e.g.StringSlice
there is one feature (???) of parsing such flags: a missing optional flag is treated the same as an explicitly specified with empty values:
note that if
--flag
is marked required, then 1st command willError: required flag(s) "oid" not set
while 2nd is still parsed as an empty slicethis not very obvious behavior can make the execution of some commands quite unexpected. For example, when command does useful actions in
for
loopExpected Behavior
when command accepts slice flag and parses each element which must not be an empty string (like container/object/user IDs), passing
--flag ""
leads to zero-len failureCurrent Behavior
if command checks flag len explicitly - fail, otherwise empty element just lost, and command may become even no-op
Possible Solution
always check length of required slice/array flags
Steps to Reproduce (for bugs)
Context
this may also appear when working with env vars:
if
OID
will be empty for some reason, this wont be detectedRegression
no
Your Environment
neofs-cli@v0.42.1
The text was updated successfully, but these errors were encountered: