Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
ciao-cli: Parse the subcommand before identifying with keystone
Browse files Browse the repository at this point in the history
This change moves the execution of common code that talks to keystone
and validates the tenant setup to after the subcommand arguments are
parsed but before the command itself is run.

This means you can get instant feedback of command line parsing errors
without any network induced delay.

Fixes: #747
  • Loading branch information
rbradford committed Oct 26, 2016
1 parent 354ffaf commit ab06400
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions ciao-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (c *command) run(args []string) error {
c.usage(cmdName)
}
args = subCmd.parseArgs(args[2:])
prepareForCommand()
return subCmd.run(args)
}

Expand Down Expand Up @@ -341,21 +342,8 @@ func checkCompulsoryOptions() {
}
}

func main() {
func prepareForCommand() {
var err error

flag.Usage = usage
flag.Parse()

getCiaoEnvVariables()
checkCompulsoryOptions()

// Print usage if no arguments are given
args := flag.Args()
if len(args) < 1 {
usage()
}

/* Load CA file if necessary */
if *caCertFile != "" {
caCert, err := ioutil.ReadFile(*caCertFile)
Expand All @@ -382,6 +370,22 @@ func main() {
if err != nil {
fatalf(err.Error())
}
}

func main() {
var err error

flag.Usage = usage
flag.Parse()

getCiaoEnvVariables()
checkCompulsoryOptions()

// Print usage if no arguments are given
args := flag.Args()
if len(args) < 1 {
usage()
}

// Find command in cmdline args
cmdName := args[0]
Expand Down

0 comments on commit ab06400

Please sign in to comment.