{"record":{"id":"5162a20430cbfd59","repo":"go-task/task","slug":"task-you-can-t-set-both-global-and-dir","errorCode":null,"errorMessage":"task: You can't set both --global and --dir","messagePattern":"task: You can't set both --global and --dir","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/flags/flags.go","lineNumber":213,"sourceCode":"}\n\n// isCI returns true if running in a CI environment\nfunc isCI() bool {\n\tci, _ := strconv.ParseBool(os.Getenv(\"CI\"))\n\treturn ci\n}\n\nfunc Validate() error {\n\tif Download && Offline {\n\t\treturn errors.New(\"task: You can't set both --download and --offline flags\")\n\t}\n\n\tif Download && ClearCache {\n\t\treturn errors.New(\"task: You can't set both --download and --clear-cache flags\")\n\t}\n\n\tif Global && Dir != \"\" {\n\t\treturn errors.New(\"task: You can't set both --global and --dir\")\n\t}\n\n\tif Output.Name != \"group\" {\n\t\tif Output.Group.Begin != \"\" {\n\t\t\treturn errors.New(\"task: You can't set --output-group-begin without --output=group\")\n\t\t}\n\t\tif Output.Group.End != \"\" {\n\t\t\treturn errors.New(\"task: You can't set --output-group-end without --output=group\")\n\t\t}\n\t\tif Output.Group.ErrorOnly {\n\t\t\treturn errors.New(\"task: You can't set --output-group-error-only without --output=group\")\n\t\t}\n\t}\n\n\tif List && ListAll {\n\t\treturn errors.New(\"task: cannot use --list and --list-all at the same time\")\n\t}\n","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/go-task/task/blob/385e5ad92af02877b6d7cf9dcc963b5ed916e70a/internal/flags/flags.go#L195-L231","documentation":"Validate() rejects combining --global with --dir. --global reads the global Taskfile from the user's home directory while --dir overrides the project directory; the combination is ambiguous so it is rejected at startup.","triggerScenarios":"Running `task --global --dir <path> ...` so flags.Global is true and flags.Dir is non-empty when Validate() executes.","commonSituations":"Shell wrappers that always set --dir to a project root while the user adds --global; scripts parameterized with an optional DIR argument that defaults to a non-empty value.","solutions":["Drop --dir and let --global use the default location","Drop --global if you intend to operate on a specific directory","Fix wrapper scripts so --dir is only passed when explicitly requested"],"exampleFix":"# before\ntask --global --dir ~/project\n\n# after\ntask --dir ~/project   # or: task --global","handlingStrategy":"validation","validationCode":"if flags.Global && flags.Dir != \"\" {\n\treturn errors.New(\"cannot combine --global with --dir\")\n}","typeGuard":null,"tryCatchPattern":"if err := flags.Validate(); err != nil {\n\tif strings.Contains(err.Error(), \"--global and --dir\") {\n\t\tfmt.Fprintln(os.Stderr, \"choose either the global Taskfile or an explicit --dir\")\n\t\tos.Exit(2)\n\t}\n\treturn err\n}","preventionTips":["Only pass --dir when explicitly set (leave it empty otherwise) in wrappers","Don't combine home-directory lookups with project-directory overrides","Use `cd` into the directory instead of --dir when already using --global elsewhere"],"tags":["cli","flags","go-task"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"385e5ad92af02877b6d7cf9dcc963b5ed916e70a","analyzedAt":"2026-09-05T09:01:05.226Z","contentChangedAt":"2026-09-05T09:01:05.226Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}