18858: Fixes positional argument retrieval on sync-users & sync-groups.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 6 Jul 2022 19:36:18 +0000 (16:36 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Wed, 6 Jul 2022 19:38:58 +0000 (16:38 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

tools/sync-groups/sync-groups.go
tools/sync-users/sync-users.go
tools/sync-users/sync-users_test.go

index e1e054a663cad7d6613899ce87366ef79c4e1242..daec5c99578fd7e3de0fb73980afa3c027c53344 100644 (file)
@@ -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 == "" {
index f9f8b6046cd376d7e3b59d002168fe237066088c..45b6e96b87331d0f76a6c95b36da642d0683f91a 100644 (file)
@@ -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 == "" {
index 1e5f688b05e6aee95e1fcee7e29abfde61f3f9cc..e5cbb77d16603818372fa56f3f700821ba5eec25 100644 (file)
@@ -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")