Commit 74d812a7 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Much smarter CLI

parent fcd86673
...@@ -160,6 +160,26 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { ...@@ -160,6 +160,26 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) {
return 1, nil return 1, nil
} }
// This variable will track whether or not we're supposed to print
// the help or not.
isHelp := false
for _, arg := range args {
if arg == "-h" || arg == "--help" {
isHelp = true
break
}
}
// Trim up to the command name
for i, v := range args {
if v[0] != '-' {
args = args[i:]
break
}
}
log.Printf("command + args: %#v", args)
version := args[0] == "version" version := args[0] == "version"
if !version { if !version {
for _, arg := range args { for _, arg := range args {
...@@ -191,12 +211,10 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { ...@@ -191,12 +211,10 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) {
// If we're supposed to print help, then print the help of the // If we're supposed to print help, then print the help of the
// command rather than running it. // command rather than running it.
for _, arg := range args { if isHelp {
if arg == "--help" || arg == "-h" {
e.ui.Say(command.Help()) e.ui.Say(command.Help())
return 0, nil return 0, nil
} }
}
log.Printf("Executing command: %s\n", args[0]) log.Printf("Executing command: %s\n", args[0])
return command.Run(e, args[1:]), nil return command.Run(e, args[1:]), nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment