Skip to content

Commit

Permalink
added check to see if cli args are empty (#56)
Browse files Browse the repository at this point in the history
* added check to see if cli args are empty

* added joshs suggested code
  • Loading branch information
meyerjrr authored Feb 25, 2022
1 parent 8773991 commit 4cbe7ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"request": "launch",
"mode": "auto",
"program": "cmd/assume/main.go",
"args": ["-c", "cf-dev", "-r=hello"],
"env": { "FORCE_NO_ALIAS": true }
},
{
Expand Down
13 changes: 10 additions & 3 deletions pkg/urfav_overrides/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ func New(name string, flags []cli.Flag, c *cli.Context) (*Flags, error) {
return nil, err
}
}

set.SetOutput(ioutil.Discard)

ca := []string{}
ca = append(ca, c.Args().Slice()...)
if c.Args().Len() > 1 {
// append the flags excluding the role arg
ca = append(ca, c.Args().Slice()[1:]...)
}

// context.Args() for this command will ONLY contain the role and any flags provided after the role
// this slice of os.Args will only contain flags and not the role if it was provided
ag := []string{}
ag = append(ag, os.Args[1:len(os.Args)-len(ca)]...)
ag = append(ag, ca[1:]...)
ag = append(ag, os.Args[1:len(os.Args)-c.Args().Len()]...)
ag = append(ag, ca...)

err := normalizeFlags(flags, set)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4cbe7ad

Please sign in to comment.