From 2a8f0321720f8ec49b4b3bd0881114e396a599ad Mon Sep 17 00:00:00 2001 From: Vyacheslav Morov Date: Tue, 7 Dec 2021 18:43:52 +0300 Subject: [PATCH] cli: Add var args to plan output. (#11631) --- .changelog/11631.txt | 3 +++ command/job_plan.go | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changelog/11631.txt diff --git a/.changelog/11631.txt b/.changelog/11631.txt new file mode 100644 index 000000000000..e67d854130eb --- /dev/null +++ b/.changelog/11631.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add `-var` and `-var-file` to the command line printed by `job plan` +``` diff --git a/command/job_plan.go b/command/job_plan.go index 9ab331de9418..b78de85c5ae8 100644 --- a/command/job_plan.go +++ b/command/job_plan.go @@ -15,7 +15,7 @@ import ( const ( jobModifyIndexHelp = `To submit the job with version verification run: -nomad job run -check-index %d %s +nomad job run -check-index %d %s%s When running the job with the check-index flag, the job will only be run if the job modify index given matches the server-side version. If the index has @@ -192,8 +192,17 @@ func (c *JobPlanCommand) Run(args []string) int { return 255 } + runArgs := strings.Builder{} + for _, varArg := range varArgs { + runArgs.WriteString(fmt.Sprintf("-var=%q ", varArg)) + } + + for _, varFile := range varFiles { + runArgs.WriteString(fmt.Sprintf("-var-file=%q ", varFile)) + } + exitCode := c.outputPlannedJob(job, resp, diff, verbose) - c.Ui.Output(c.Colorize().Color(formatJobModifyIndex(resp.JobModifyIndex, path))) + c.Ui.Output(c.Colorize().Color(formatJobModifyIndex(resp.JobModifyIndex, runArgs.String(), path))) return exitCode } @@ -333,8 +342,8 @@ func getExitCode(resp *api.JobPlanResponse) int { // formatJobModifyIndex produces a help string that displays the job modify // index and how to submit a job with it. -func formatJobModifyIndex(jobModifyIndex uint64, jobName string) string { - help := fmt.Sprintf(jobModifyIndexHelp, jobModifyIndex, jobName) +func formatJobModifyIndex(jobModifyIndex uint64, args string, jobName string) string { + help := fmt.Sprintf(jobModifyIndexHelp, jobModifyIndex, args, jobName) out := fmt.Sprintf("[reset][bold]Job Modify Index: %d[reset]\n%s", jobModifyIndex, help) return out }