From 38c81cf3e3ad8830a7588e8318070ebccb2872ae Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Fri, 16 Oct 2015 17:32:36 -0700 Subject: [PATCH] Move ConfigFile() and ConfigDir() from package main to packer --- checkpoint.go | 3 ++- config.go | 15 +-------------- main.go | 2 +- packer/config_file.go | 14 ++++++++++++++ config_unix.go => packer/config_file_unix.go | 2 +- .../config_file_windows.go | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 packer/config_file.go rename config_unix.go => packer/config_file_unix.go (98%) rename config_windows.go => packer/config_file_windows.go (98%) diff --git a/checkpoint.go b/checkpoint.go index f8db2be28..87ef594c2 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/go-checkpoint" "github.com/mitchellh/packer/command" + "github.com/mitchellh/packer/packer" ) func init() { @@ -25,7 +26,7 @@ func runCheckpoint(c *config) { return } - configDir, err := ConfigDir() + configDir, err := packer.ConfigDir() if err != nil { log.Printf("[ERR] Checkpoint setup error: %s", err) checkpointResult <- nil diff --git a/config.go b/config.go index efb4e7d31..62b92d9f5 100644 --- a/config.go +++ b/config.go @@ -25,19 +25,6 @@ type config struct { Provisioners map[string]string } -// ConfigFile returns the default path to the configuration file. On -// Unix-like systems this is the ".packerconfig" file in the home directory. -// On Windows, this is the "packer.config" file in the application data -// directory. -func ConfigFile() (string, error) { - return configFile() -} - -// ConfigDir returns the configuration directory for Packer. -func ConfigDir() (string, error) { - return configDir() -} - // Decodes configuration in JSON format from the given io.Reader into // the config object pointed to. func decodeConfig(r io.Reader, c *config) error { @@ -64,7 +51,7 @@ func (c *config) Discover() error { } // Next, look in the plugins directory. - dir, err := ConfigDir() + dir, err := packer.ConfigDir() if err != nil { log.Printf("[ERR] Error loading config directory: %s", err) } else { diff --git a/main.go b/main.go index a0d3190d1..69bec4a8d 100644 --- a/main.go +++ b/main.go @@ -223,7 +223,7 @@ func loadConfig() (*config, error) { configFilePath := os.Getenv("PACKER_CONFIG") if configFilePath == "" { var err error - configFilePath, err = configFile() + configFilePath, err = packer.ConfigFile() if err != nil { log.Printf("Error detecting default config file path: %s", err) diff --git a/packer/config_file.go b/packer/config_file.go new file mode 100644 index 000000000..f5d36e9e4 --- /dev/null +++ b/packer/config_file.go @@ -0,0 +1,14 @@ +package packer + +// ConfigFile returns the default path to the configuration file. On +// Unix-like systems this is the ".packerconfig" file in the home directory. +// On Windows, this is the "packer.config" file in the application data +// directory. +func ConfigFile() (string, error) { + return configFile() +} + +// ConfigDir returns the configuration directory for Packer. +func ConfigDir() (string, error) { + return configDir() +} diff --git a/config_unix.go b/packer/config_file_unix.go similarity index 98% rename from config_unix.go rename to packer/config_file_unix.go index 2c8a7a304..82260c2a2 100644 --- a/config_unix.go +++ b/packer/config_file_unix.go @@ -1,6 +1,6 @@ // +build darwin freebsd linux netbsd openbsd -package main +package packer import ( "bytes" diff --git a/config_windows.go b/packer/config_file_windows.go similarity index 98% rename from config_windows.go rename to packer/config_file_windows.go index fa3ab94b7..d0bcc1c50 100644 --- a/config_windows.go +++ b/packer/config_file_windows.go @@ -1,6 +1,6 @@ // +build windows -package main +package packer import ( "path/filepath"