cli: add -json-output and -t flags to nomad job plan#27957
Open
ilya-shevelev wants to merge 1 commit into
Open
cli: add -json-output and -t flags to nomad job plan#27957ilya-shevelev wants to merge 1 commit into
ilya-shevelev wants to merge 1 commit into
Conversation
Add output formatting options to `nomad job plan` so users can get the plan result as JSON or formatted via Go templates. The existing `-json` flag is used for input parsing, so a new `-json-output` flag is introduced for output formatting to avoid conflicts. The `-t` flag enables Go template formatting, consistent with other commands like `nomad job inspect`. Both flags work for single-region and multi-region plans, and the existing human-readable output remains the default. Closes hashicorp#27369 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
Member
|
Waiting on a CLA signature on this still. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-json-outputflag tonomad job planfor JSON-formatted output of the plan response-tflag for Go template formatting, consistent withnomad job inspect-jsonflag for input parsing (JSON jobfile format) — no conflictCloses #27369
Details
The
nomad job plancommand previously only supported human-readable output, making it difficult to programmatically parse plan results. This PR adds two new output formatting options:-json-output: Outputs the fullapi.JobPlanResponseas JSON. Named differently from-jsonto avoid the existing input flag conflict.-t: Formats output using a Go template (e.g.,-t '{{.Diff.ID}}'), consistent with hownomad job inspectworks.Using both flags simultaneously returns an error. When neither flag is specified, the existing human-readable output is preserved.
For multi-region plans, the output is a
map[string]*api.JobPlanResponsekeyed by region name.Test plan
TestPlanCommand_JsonOutputAndTemplateMutuallyExclusive— verifies error on combined flagsTestPlanCommand_JsonOutput— e2e test: plans a job, verifies valid JSON outputTestPlanCommand_TemplateOutput— e2e test: plans a job with-t, verifies template renders correctly