Skip to content

Commit

Permalink
feat: default to client command when none given
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Oct 28, 2021
1 parent eddbaba commit 1d5ca4c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion bin/vproxy/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,30 @@ func parseFlags() {
printVersion(c)
}

err := app.Run(os.Args)
// default to 'client' command when none given
bin := os.Args[0]
args := os.Args[1:]
if len(args) == 0 {
args = append(os.Args, "client")
} else if !isValidCommand(args[0], app) {
args = append([]string{bin, "client"}, args...)
}

err := app.Run(args)
if err != nil {
fmt.Printf("error: %s\n", err)
os.Exit(1)
}
}

// search command names and aliases for the given string
func isValidCommand(cmd string, app *cli.App) bool {
for _, command := range app.Commands {
for _, c := range command.Names() {
if c == cmd {
return true
}
}
}
return false
}
2 changes: 1 addition & 1 deletion bin/vproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func startClient(c *cli.Context) error {
reBind := regexp.MustCompile("^.*?:[0-9]+$")
for _, bind := range binds {
if bind == "" || !reBind.MatchString(bind) {
return fmt.Errorf("error: invalid binding: '%s' (expected format 'app.local.com:7000')", bind)
return fmt.Errorf("invalid binding: '%s' (expected format 'app.local.com:7000')", bind)
}
}

Expand Down

0 comments on commit 1d5ca4c

Please sign in to comment.