From: Lucas Di Pentima Date: Wed, 6 Jul 2022 19:36:18 +0000 (-0300) Subject: 18858: Fixes positional argument retrieval on sync-users & sync-groups. X-Git-Tag: 2.5.0~121^2~4 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/c592128fda794f2679a117a881c2f7d86ae091e0 18858: Fixes positional argument retrieval on sync-users & sync-groups. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/tools/sync-groups/sync-groups.go b/tools/sync-groups/sync-groups.go index e1e054a663..daec5c9957 100644 --- a/tools/sync-groups/sync-groups.go +++ b/tools/sync-groups/sync-groups.go @@ -181,8 +181,10 @@ func ParseFlags(config *ConfigParams) error { // Input file as a required positional argument if flags.NArg() == 0 { return fmt.Errorf("please provide a path to an input file") + } else if flags.NArg() > 1 { + return fmt.Errorf("please provide just one input file argument") } - srcPath := &os.Args[flags.NFlag()+1] + srcPath := &os.Args[len(os.Args)-1] // Validations if *srcPath == "" { diff --git a/tools/sync-users/sync-users.go b/tools/sync-users/sync-users.go index f9f8b6046c..45b6e96b87 100644 --- a/tools/sync-users/sync-users.go +++ b/tools/sync-users/sync-users.go @@ -123,8 +123,10 @@ func ParseFlags(cfg *ConfigParams) error { // Input file as a required positional argument if flags.NArg() == 0 { return fmt.Errorf("please provide a path to an input file") + } else if flags.NArg() > 1 { + return fmt.Errorf("please provide just one input file argument") } - srcPath := &os.Args[flags.NFlag()+1] + srcPath := &os.Args[len(os.Args)-1] // Validations if *srcPath == "" { diff --git a/tools/sync-users/sync-users_test.go b/tools/sync-users/sync-users_test.go index 1e5f688b05..e5cbb77d16 100644 --- a/tools/sync-users/sync-users_test.go +++ b/tools/sync-users/sync-users_test.go @@ -102,7 +102,7 @@ func (s *TestSuite) TestParseFlagsWithoutPositionalArgument(c *C) { } func (s *TestSuite) TestParseFlagsWrongUserID(c *C) { - os.Args = []string{"cmd", "-user-id=nickname", "/tmp/somefile.csv"} + os.Args = []string{"cmd", "-user-id", "nickname", "/tmp/somefile.csv"} err := ParseFlags(&ConfigParams{}) c.Assert(err, NotNil) c.Assert(err, ErrorMatches, ".*user ID must be one of:.*") @@ -122,7 +122,7 @@ func (s *TestSuite) TestParseFlagsWithPositionalArgument(c *C) { func (s *TestSuite) TestParseFlagsWithOptionalFlags(c *C) { cfg := ConfigParams{} - os.Args = []string{"cmd", "-verbose", "-deactivate-unlisted", "-user-id=username", "/tmp/somefile.csv"} + os.Args = []string{"cmd", "-verbose", "-deactivate-unlisted", "-user-id", "username", "/tmp/somefile.csv"} err := ParseFlags(&cfg) c.Assert(err, IsNil) c.Assert(cfg.Path, Equals, "/tmp/somefile.csv")