Move ConfigFile() and ConfigDir() from package main to packer

This commit is contained in:
Mark Peek 2015-10-16 17:32:36 -07:00
parent 82a7f6ef97
commit 38c81cf3e3
6 changed files with 20 additions and 18 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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)

14
packer/config_file.go Normal file
View File

@ -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()
}

View File

@ -1,6 +1,6 @@
// +build darwin freebsd linux netbsd openbsd
package main
package packer
import (
"bytes"

View File

@ -1,6 +1,6 @@
// +build windows
package main
package packer
import (
"path/filepath"