{"record":{"id":"60261f105fe3195a","repo":"hashicorp/nomad","slug":"the-template-flag-is-only-valid-when-using-go-60261f","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_list.go","lineNumber":292,"sourceCode":"\t\tif ns == \"*\" {\n\t\t\treturn fmt.Sprintf(\"%s|%s\", v.Namespace, v.Path)\n\t\t}\n\t\treturn v.Path\n\t}\n\n\t// Reduce the items slice to a string slice containing only the\n\t// variable paths.\n\tpList := make([]string, len(vars))\n\tfor i, sv := range vars {\n\t\tpList[i] = toPathStr(sv)\n\t}\n\n\treturn pList\n}\n\nfunc (c *VarListCommand) validateOutputFlag() error {\n\tif c.outFmt != \"go-template\" && c.tmpl != \"\" {\n\t\treturn errors.New(errUnexpectedTemplate)\n\t}\n\tswitch c.outFmt {\n\tcase \"json\", \"terse\", \"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(errInvalidListOutFormat)\n\t}\n}\n","sourceCodeStart":274,"sourceCodeEnd":306,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_list.go#L274-L306","documentation":"VarListCommand.validateOutputFlag rejects the -template flag when the -output format is not go-template. Templates only apply to go-template rendering, so combining them with json/terse/table output is a user error caught before execution.","triggerScenarios":"Running `vault kv list -template=... -output=json|terse|table <path>` (c.outFmt != go-template and c.tmpl != \"\").","commonSituations":"Reusing a shared command-line wrapper that always sets -template; switching a list command from go-template to terse output for scripting but leaving the template flag behind.","solutions":["Remove the -template flag when output is json/terse/table","Or set -output=go-template so the template is honored","Post-process json/terse output with jq or similar instead"],"exampleFix":"// before\nvault kv list -output=terse -template='{{ range . }}{{ . }}{{ end }}' secret/\n// after\nvault kv list -output=terse secret/","handlingStrategy":"validation","validationCode":"if outFmt != \"go-template\" && tmpl != \"\" {\n\treturn fmt.Errorf(\"-template requires -output=go-template, got %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// retry without -template\n\t}\n\treturn err\n}","preventionTips":["Strip -template when switching list output to json/terse/table","Use distinct wrapper functions per output format","Test flag combinations 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"}