{"record":{"id":"4f38fa13ea6568cf","repo":"hashicorp/nomad","slug":"the-template-flag-is-only-valid-when-using-go-4f38fa","errorCode":null,"errorMessage":"The '-template' flag is only valid when using 'go-template' formatting","messagePattern":"The '-template' flag is only valid when using 'go-template' formatting","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_put.go","lineNumber":601,"sourceCode":"\t\tc.inFmt = \"hcl\"\n\tdefault:\n\t\treturn fmt.Errorf(\"Unable to determine format of %s; Use the -in flag to specify it.\", arg)\n\t}\n\treturn nil\n}\n\nfunc (c *VarPutCommand) validateInputFlag() error {\n\tswitch c.inFmt {\n\tcase \"hcl\", \"json\":\n\t\treturn nil\n\tdefault:\n\t\treturn errors.New(errInvalidInFormat)\n\t}\n}\n\nfunc (c *VarPutCommand) validateOutputFlag() error {\n\tif c.outFmt != \"go-template\" && c.tmpl != \"\" {\n\t\treturn errors.New(errUnexpectedTemplate)\n\t}\n\tswitch c.outFmt {\n\tcase \"none\", \"json\", \"hcl\", \"table\":\n\t\treturn nil\n\tcase \"go-template\":\n\t\tif c.tmpl == \"\" {\n\t\t\treturn errors.New(errMissingTemplate)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn errors.New(errInvalidOutFormat)\n\t}\n}\n\nfunc warnInvalidIdentifier(in string) error {\n\tinvalid := invalidIdentifier.FindAllString(in, -1)\n\tif len(invalid) == 0 {\n\t\treturn nil","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_put.go#L583-L619","documentation":"VarPutCommand.validateOutputFlag rejects -template when -output is not go-template (allowed non-template formats: none, json, hcl, table). The template flag only applies to go-template rendering, so mismatched combinations fail fast.","triggerScenarios":"Running `vault kv put -template=... -output=json|hcl|none|table ...` (c.outFmt != go-template and c.tmpl != \"\").","commonSituations":"Shared scripts that always append -template; switching put output to json for automation while the template flag remains; copy-paste from a get command that used go-template.","solutions":["Remove -template when using json/hcl/none/table output","Or set -output=go-template with a valid template","Post-process json output with jq instead of templating"],"exampleFix":"// before\nvault kv put -in=hcl -output=json -template='{{ .Data }}' secret/foo @spec.hcl\n// after\nvault kv put -in=hcl -output=json secret/foo @spec.hcl","handlingStrategy":"validation","validationCode":"if outFmt != \"go-template\" && tmpl != \"\" {\n\treturn fmt.Errorf(\"-template requires -output=go-template, got %q\", outFmt)\n}\nswitch outFmt {\ncase \"none\", \"json\", \"hcl\", \"table\", \"go-template\":\n\t// ok\ndefault:\n\treturn fmt.Errorf(\"invalid -out %q\", outFmt)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.validateOutputFlag(); err != nil {\n\tif strings.Contains(err.Error(), \"'-template' flag is only valid\") {\n\t\t// drop -template and retry\n\t}\n\treturn err\n}","preventionTips":["Pass -template only with -output=go-template","Avoid unconditional flag injection in shared scripts","Add combination tests for flag pairs in CI"],"tags":["go","cli","flags","validation"],"backgroundTag":"invalid-flag-combination","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}