{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/arguments/workspace_list.go#L21-L49","documentation":"Returned by ParseWorkspaceList (workspace_list.go:39) when 'terraform workspace list' is given any positional arguments. Historically 'workspace list' accepted a DIR argument; that was replaced by the global -chdir flag, so the error suggests -chdir. The command now takes no positionals.","triggerScenarios":"Line 37-39: cmdFlags.Args() is non-empty after flag parsing -> the error is appended. Triggered by e.g. 'terraform workspace list ./my-dir'.","commonSituations":"User following an old tutorial that passes a path to 'workspace list'; muscle memory from 'terraform init DIR'; trying to list workspaces for a different directory by position rather than -chdir.","solutions":["Use the global -chdir flag to switch directories: 'terraform -chdir=./my-dir workspace list'.","cd into the target directory first, then run 'terraform workspace list' with no arguments.","Remove any positional path argument from the command line."],"exampleFix":"# before\n$ terraform workspace list ./my-dir\n# after\n$ terraform -chdir=./my-dir workspace list","handlingStrategy":"validation","validationCode":"// 'workspace list' takes no positionals; redirect legacy DIR usage to -chdir.\nfunc normalizeListArgs(args []string) ([]string, []string) {\n    var positionals []string\n    for _, a := range args {\n        if strings.HasPrefix(a, \"-\") { continue }\n        positionals = append(positionals, a)\n    }\n    if len(positionals) > 0 {\n        return []string{\"-chdir=\" + positionals[0], \"workspace\", \"list\"}, nil\n    }\n    return append([]string{\"workspace\", \"list\"}, args...), nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'terraform -chdir=DIR workspace list' instead of passing DIR positionally.","Update docs/scripts that follow the old 'workspace list DIR' convention.","Cd into the target directory when in doubt."],"tags":["cli-arguments","workspace","list","chdir","deprecation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}