Skip to content

Commit

Permalink
Fix parsing of negative values for duration flags (#2471)
Browse files Browse the repository at this point in the history
* Fix parsing of negative values for duration flags

* In order to be backward compatible with Golang flags, for flags that
  are specified using single hyphens, we add another hyphen so that
  pflag can process it correctly. This augmentation must be done on
  flags and not on values. The way we currently do that is we determine
  all args that are prefixed with a single hyphen and are not numbers
  since negative numbers are prefixed with hyphens. This logic however
  doesn't work for duration flags since a duration such as -1s is a
  valid duration, not parseable as a number and yet since it's a value
  and not a flag, should not be prefixed with an additional hyphen. This
  PR makes the aforementioned logic more robust by compiling a list of
  flags and adding an additional hyphen only if the arg is a flag.
* Add tests for each supported data type.
  • Loading branch information
kislaykishore authored Sep 12, 2024
1 parent e5fd84f commit f4c0f16
Show file tree
Hide file tree
Showing 27 changed files with 901 additions and 113 deletions.
2 changes: 1 addition & 1 deletion cmd/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getConfigObject(t *testing.T, args []string) (*cfg.Config, error) {
require.Nil(t, err)
cmdArgs := append([]string{"gcsfuse"}, args...)
cmdArgs = append(cmdArgs, "a")
cmd.SetArgs(ConvertToPosixArgs(cmdArgs))
cmd.SetArgs(ConvertToPosixArgs(cmdArgs, cmd))
if err = cmd.Execute(); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit f4c0f16

Please sign in to comment.