Commit 25868e1a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

ConfigDir

parent 5afcac3f
...@@ -23,6 +23,19 @@ type config struct { ...@@ -23,6 +23,19 @@ type config struct {
Provisioners map[string]string 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 // Decodes configuration in JSON format from the given io.Reader into
// the config object pointed to. // the config object pointed to.
func decodeConfig(r io.Reader, c *config) error { func decodeConfig(r io.Reader, c *config) error {
...@@ -35,11 +48,6 @@ func decodeConfig(r io.Reader, c *config) error { ...@@ -35,11 +48,6 @@ func decodeConfig(r io.Reader, c *config) error {
// This looks in the directory of the executable and the CWD, in that // This looks in the directory of the executable and the CWD, in that
// order for priority. // order for priority.
func (c *config) Discover() error { func (c *config) Discover() error {
// Look in the cwd.
if err := c.discover("."); err != nil {
return err
}
// Next, look in the same directory as the executable. Any conflicts // Next, look in the same directory as the executable. Any conflicts
// will overwrite those found in our current directory. // will overwrite those found in our current directory.
exePath, err := osext.Executable() exePath, err := osext.Executable()
...@@ -51,6 +59,21 @@ func (c *config) Discover() error { ...@@ -51,6 +59,21 @@ func (c *config) Discover() error {
} }
} }
// Look in the plugins directory
dir, err := ConfigDir()
if err != nil {
log.Printf("[ERR] Error loading config directory: %s", err)
} else {
if err := c.discover(filepath.Join(dir, "plugins")); err != nil {
return err
}
}
// Look in the cwd.
if err := c.discover("."); err != nil {
return err
}
return nil return nil
} }
......
package main
// 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()
}
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