packer: PACKER_LOG to toggle logging from an env var [GH-3]
This commit is contained in:
parent
7dfeda350a
commit
947209a028
|
@ -5,12 +5,21 @@ import (
|
|||
"github.com/mitchellh/packer/packer"
|
||||
"github.com/mitchellh/packer/packer/plugin"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if os.Getenv("PACKER_LOG") == "" {
|
||||
// If we don't have logging explicitly enabled, then disable it
|
||||
log.SetOutput(ioutil.Discard)
|
||||
} else {
|
||||
// Logging is enabled, make sure it goes to stderr
|
||||
log.SetOutput(os.Stderr)
|
||||
}
|
||||
|
||||
defer plugin.CleanupClients()
|
||||
|
||||
commands := map[string]string {
|
||||
|
|
|
@ -4,6 +4,7 @@ package packer
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -87,6 +88,8 @@ func (e *coreEnvironment) Builder(name string) (b Builder, err error) {
|
|||
// Executes a command as if it was typed on the command-line interface.
|
||||
// The return value is the exit code of the command.
|
||||
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" {
|
||||
e.printHelp()
|
||||
return 1, nil
|
||||
|
@ -115,6 +118,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) {
|
|||
|
||||
// If we still don't have a command, show the help.
|
||||
if command == nil {
|
||||
log.Printf("Environment.CLI: command not found: %s\n", args[0])
|
||||
e.printHelp()
|
||||
return 1, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue