Skip to content

Commit

Permalink
Merge pull request #180 from rkettelerij/multiple_var_files
Browse files Browse the repository at this point in the history
#179 Support multiple var-files
  • Loading branch information
jrasell committed Jun 20, 2018
2 parents e9febe0 + cba2067 commit 5e422a6
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 109 deletions.
117 changes: 104 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ General Options:
-var-file=<file>
Used in conjunction with the -job-file will deploy a templated job to your
Nomad cluster. [default: levant.(yaml|yml|tf)]
Nomad cluster. You can repeat this flag multiple times to supply multiple var-files.
[default: levant.(yaml|yml|tf)]
`
return strings.TrimSpace(helpText)
}
Expand All @@ -94,7 +95,7 @@ func (c *DeployCommand) Run(args []string) int {
flags.BoolVar(&config.ForceCount, "force-count", false, "")
flags.StringVar(&config.LogLevel, "log-level", "INFO", "")
flags.StringVar(&config.LogFormat, "log-format", "HUMAN", "")
flags.StringVar(&config.VaiableFile, "var-file", "", "")
flags.Var((*helper.FlagStringSlice)(&config.VariableFiles), "var-file", "")

if err = flags.Parse(args); err != nil {
return 1
Expand All @@ -120,7 +121,7 @@ func (c *DeployCommand) Run(args []string) int {
return 1
}

config.Job, err = template.RenderJob(config.TemplateFile, config.VaiableFile, addr, &c.Meta.flagVars)
config.Job, err = template.RenderJob(config.TemplateFile, config.VariableFiles, addr, &c.Meta.flagVars)
if err != nil {
c.UI.Error(fmt.Sprintf("[ERROR] levant/command: %v", err))
return 1
Expand Down
4 changes: 2 additions & 2 deletions command/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDeploy_checkCanaryAutoPromote(t *testing.T) {
}

for i, c := range cases {
job, err := template.RenderJob(c.File, "", "", &fVars)
job, err := template.RenderJob(c.File, []string{}, "", &fVars)
if err != nil {
t.Fatalf("case %d failed: %v", i, err)
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestDeploy_checkForceBatch(t *testing.T) {
}

for i, c := range cases {
job, err := template.RenderJob(c.File, "", "", &fVars)
job, err := template.RenderJob(c.File, []string{}, "", &fVars)
if err != nil {
t.Fatalf("case %d failed: %v", i, err)
}
Expand Down
8 changes: 5 additions & 3 deletions command/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ General Options:
rendered to stdout if this is not set.
-var-file=<file>
The variables file to render the template with. [default: levant.(yaml|yml|tf)]
The variables file to render the template with. You can repeat this flag multiple
times to supply multiple var-files. [default: levant.(yaml|yml|tf)]
`
return strings.TrimSpace(helpText)
}
Expand All @@ -57,15 +58,16 @@ func (c *RenderCommand) Synopsis() string {
// Run triggers a run of the Levant template functions.
func (c *RenderCommand) Run(args []string) int {

var addr, variables, outPath, templateFile string
var addr, outPath, templateFile string
var variables []string
var err error
var tpl *bytes.Buffer

flags := c.Meta.FlagSet("render", FlagSetVars)
flags.Usage = func() { c.UI.Output(c.Help()) }

flags.StringVar(&addr, "consul-address", "", "")
flags.StringVar(&variables, "var-file", "", "")
flags.Var((*helper.FlagStringSlice)(&variables), "var-file", "")
flags.StringVar(&outPath, "out", "", "")

if err = flags.Parse(args); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions helper/kvflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ func (v *Flag) Set(raw string) error {
(*v)[key] = value
return nil
}

// FlagStringSlice is a flag.Value implementation for parsing targets from the
// command line, e.g. -var-file=aa -var-file=bb
type FlagStringSlice []string

func (v *FlagStringSlice) String() string {
return ""
}
func (v *FlagStringSlice) Set(raw string) error {
*v = append(*v, raw)
return nil
}
4 changes: 2 additions & 2 deletions levant/structs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Config struct {
// before being deployed to the cluster.
TemplateFile string

// VaiableFile contains the variables which will be substituted into the
// VariableFiles contains the variables which will be substituted into the
// templateFile before deployment.
VaiableFile string
VariableFiles []string
}
Loading

0 comments on commit 5e422a6

Please sign in to comment.