{"record":{"id":"de2b9f063b17a085","repo":"hashicorp/nomad","slug":"the-template-flag-is-only-valid-when-using-go","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_get.go","lineNumber":203,"sourceCode":"\tc.Ui.Output(out)\n\n\thint, _ := c.Meta.showUIPath(UIHintContext{\n\t\tCommand: \"var get\",\n\t\tPathParams: map[string]string{\n\t\t\t\"path\":      path,\n\t\t\t\"namespace\": sv.Namespace,\n\t\t},\n\t\tOpenURL: openURL,\n\t})\n\tif hint != \"\" {\n\t\tc.Ui.Warn(hint)\n\t}\n\treturn 0\n}\n\nfunc (c *VarGetCommand) validateOutputFlag() error {\n\tif c.outFmt != \"go-template\" && c.tmpl != \"\" {\n\t\treturn errors.New(errUnexpectedTemplate)\n\t}\n\tswitch c.outFmt {\n\tcase \"hcl\", \"json\", \"none\", \"table\":\n\t\treturn nil\n\tcase \"go-template\": //noop - needs more validation\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 (c *VarGetCommand) GetConcurrentUI() cli.ConcurrentUi {\n\treturn cli.ConcurrentUi{Ui: c.Ui}\n}\n","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_get.go#L185-L221","documentation":"VarGetCommand.validateOutputFlag rejects the -template flag when the -output format is anything other than go-template. The template only has meaning for go-template rendering, so supplying it with hcl/json/none/table output is treated as a user mistake and fails fast before talking to the server.","triggerScenarios":"Running `vault kv get -template=... -output=hcl|json|none|table <path>` (or setting c.tmpl while c.outFmt is not go-template).","commonSituations":"Copy-pasting a command line that previously used -template and switching -output to json for scripting; automation scripts that always pass -template regardless of format.","solutions":["Remove the -template flag when using a non-go-template -output","Or change -output to go-template so the template is used","For structured output, drop the template and post-process JSON/HCL instead"],"exampleFix":"// before\nvault kv get -output=json -template='{{ .Data.data }}' secret/foo\n// after\nvault kv get -output=json secret/foo | jq -r '.data.data'","handlingStrategy":"validation","validationCode":"valid := []string{\"go-template\",\"hcl\",\"json\",\"none\",\"table\"}\nif outFmt != \"go-template\" && tmpl != \"\" {\n\treturn fmt.Errorf(\"-template requires -output=go-template, got %q\", outFmt)\n}\nif !slices.Contains(valid, outFmt) {\n\treturn fmt.Errorf(\"invalid -output %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 or switch to go-template and retry\n\t}\n\treturn err\n}","preventionTips":["Only pass -template together with -output=go-template","Lint shell wrappers that add flags unconditionally","Validate flag combinations in CI by running commands with -h or dry parsing"],"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"}