From aa1304f86006b4918a795735d370ffc277a80bcc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 2 Jun 2013 11:49:01 -0700 Subject: [PATCH] packer: Print command help if "--help" is given --- packer/environment.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packer/environment.go b/packer/environment.go index 2af79f628..5be574bf1 100644 --- a/packer/environment.go +++ b/packer/environment.go @@ -154,7 +154,8 @@ func (e *coreEnvironment) Provisioner(name string) (p Provisioner, err error) { func (e *coreEnvironment) Cli(args []string) (result int, err error) { log.Printf("Environment.Cli: %#v\n", args) - if len(args) == 0 || args[0] == "--help" || args[0] == "-h" { + // If we have no arguments, just short-circuit here and print the help + if len(args) == 0 { e.printHelp() return 1, nil } @@ -188,6 +189,15 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { } } + // If we're supposed to print help, then print the help of the + // command rather than running it. + for _, arg := range args { + if arg == "--help" || arg == "-h" { + e.ui.Say(command.Help()) + return 0, nil + } + } + log.Printf("Executing command: %s\n", args[0]) return command.Run(e, args[1:]), nil }