From ab06400499de69ae9548da2baf10373728d69410 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 26 Oct 2016 15:56:53 +0100 Subject: [PATCH] ciao-cli: Parse the subcommand before identifying with keystone 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 --- ciao-cli/main.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ciao-cli/main.go b/ciao-cli/main.go index 4d8eb9fa5..6c37ea975 100644 --- a/ciao-cli/main.go +++ b/ciao-cli/main.go @@ -51,6 +51,7 @@ func (c *command) run(args []string) error { c.usage(cmdName) } args = subCmd.parseArgs(args[2:]) + prepareForCommand() return subCmd.run(args) } @@ -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) @@ -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]