{"record":{"id":"619a7918c7a498df","repo":"hashicorp/terraform","slug":"too-many-command-line-arguments-did-you-mean-to-u","errorCode":null,"errorMessage":"Too many command line arguments. Did you mean to use -chdir?","messagePattern":"Too many command line arguments\\. Did you mean to use -chdir\\?","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/arguments/workspace_list.go","lineNumber":39,"sourceCode":"\tvar diags tfdiags.Diagnostics\n\n\tvar jsonOutput bool\n\tcmdFlags := defaultFlagSet(\"workspace list\")\n\tcmdFlags.BoolVar(&jsonOutput, \"json\", false, \"produce JSON output\")\n\n\tif err := cmdFlags.Parse(args); err != nil {\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\terr.Error(),\n\t\t))\n\t}\n\n\t// `workspace list` takes no positional arguments. Historically there was a DIR argument that was replaced with the -chdir flag.\n\t// Here we replicate the old behaviour of suggesting the user to use -chdir if they provide any positional arguments.\n\targs = cmdFlags.Args()\n\tif len(args) != 0 {\n\t\tdiags = diags.Append(errors.New(\"Too many command line arguments. Did you mean to use -chdir?\"))\n\t}\n\n\tswitch {\n\tcase jsonOutput:\n\t\treturn &WorkspaceList{Workspace: Workspace{ViewType: ViewJSON}}, diags\n\tdefault:\n\t\treturn &WorkspaceList{Workspace: Workspace{ViewType: ViewHuman}}, diags\n\t}\n}\n","sourceCodeStart":21,"sourceCodeEnd":49,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/arguments/workspace_list.go#L21-L49","documentation":"Returned at workspace_list.go:39 when 'terraform workspace list' is invoked with any positional arguments. The command takes no positional arguments; historically there was a DIR argument that was replaced by the global -chdir flag. The error message suggests -chdir to guide users who may be relying on the old behavior.","triggerScenarios":"Running 'terraform workspace list .' or 'terraform workspace list /path/to/dir'. workspace_list.go:37-38 checks 'len(args) != 0' after flag parsing and appends this error.","commonSituations":"Users upgrading from very old terraform versions where 'workspace list' accepted a directory; muscle memory from 'terraform env list'; confusion about where to specify the working directory.","solutions":["Use the -chdir global flag: 'terraform -chdir=/path/to/dir workspace list'.","Omit positional arguments entirely: 'terraform workspace list'.","cd into the target directory before running the command."],"exampleFix":"// before\nterraform workspace list /path/to/config\n// error: Too many command line arguments. Did you mean to use -chdir?\n\n// after\nterraform -chdir=/path/to/config workspace list","handlingStrategy":"validation","validationCode":"// Use -chdir instead of positional args for workspace list:\n// exec.Command(\"terraform\", \"-chdir=\"+dir, \"workspace\", \"list\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the -chdir global flag instead of positional directory arguments.","Update scripts that rely on pre-0.10 workspace command syntax.","Document the -chdir flag for teams migrating from older terraform versions."],"tags":["terraform","cli","workspace","argument-validation","chdir"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}