Commit 73c5192b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/push: add base_dir setting

parent f76116e4
...@@ -86,15 +86,32 @@ func (c *PushCommand) Run(args []string) int { ...@@ -86,15 +86,32 @@ func (c *PushCommand) Run(args []string) int {
archiveTemplateEntry: args[0], archiveTemplateEntry: args[0],
} }
// Determine the path we're archiving // Determine the path we're archiving. This logic is a bit complicated
// as there are three possibilities:
//
// 1.) BaseDir is an absolute path, just use that.
//
// 2.) BaseDir is empty, so we use the directory of the template.
//
// 3.) BaseDir is relative, so we use the path relative to the directory
// of the template.
//
path := tpl.Push.BaseDir path := tpl.Push.BaseDir
if path == "" { if path == "" || !filepath.IsAbs(path) {
path, err = filepath.Abs(args[0]) tplPath, err := filepath.Abs(args[0])
if err != nil {
c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err))
return 1
}
tplPath = filepath.Dir(tplPath)
if path != "" {
tplPath = filepath.Join(tplPath, path)
}
path, err = filepath.Abs(tplPath)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err)) c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err))
return 1 return 1
} }
path = filepath.Dir(path)
} }
// Build the upload options // Build the upload options
......
...@@ -46,7 +46,7 @@ type Template struct { ...@@ -46,7 +46,7 @@ type Template struct {
type PushConfig struct { type PushConfig struct {
Name string Name string
Address string Address string
BaseDir string BaseDir string `mapstructure:"base_dir"`
Include []string Include []string
Exclude []string Exclude []string
Token string Token string
......
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