go-task/task · error

task: You can't set both --global and --dir

Error message

task: You can't set both --global and --dir

What it means

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.

Source

Thrown at internal/flags/flags.go:213

}

// isCI returns true if running in a CI environment
func isCI() bool {
	ci, _ := strconv.ParseBool(os.Getenv("CI"))
	return ci
}

func Validate() error {
	if Download && Offline {
		return errors.New("task: You can't set both --download and --offline flags")
	}

	if Download && ClearCache {
		return errors.New("task: You can't set both --download and --clear-cache flags")
	}

	if Global && Dir != "" {
		return errors.New("task: You can't set both --global and --dir")
	}

	if Output.Name != "group" {
		if Output.Group.Begin != "" {
			return errors.New("task: You can't set --output-group-begin without --output=group")
		}
		if Output.Group.End != "" {
			return errors.New("task: You can't set --output-group-end without --output=group")
		}
		if Output.Group.ErrorOnly {
			return errors.New("task: You can't set --output-group-error-only without --output=group")
		}
	}

	if List && ListAll {
		return errors.New("task: cannot use --list and --list-all at the same time")
	}

View on GitHub (pinned to 385e5ad92a)

Solutions

  1. Drop --dir and let --global use the default location
  2. Drop --global if you intend to operate on a specific directory
  3. Fix wrapper scripts so --dir is only passed when explicitly requested

Example fix

# before
task --global --dir ~/project

# after
task --dir ~/project   # or: task --global
Defensive patterns

Strategy: validation

Validate before calling

if flags.Global && flags.Dir != "" {
	return errors.New("cannot combine --global with --dir")
}

Try / catch

if err := flags.Validate(); err != nil {
	if strings.Contains(err.Error(), "--global and --dir") {
		fmt.Fprintln(os.Stderr, "choose either the global Taskfile or an explicit --dir")
		os.Exit(2)
	}
	return err
}

Prevention

When it happens

Trigger: Running `task --global --dir <path> ...` so flags.Global is true and flags.Dir is non-empty when Validate() executes.

Common situations: 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.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of go-task/task@385e5ad92a (2026-09-05). Data as JSON: /api/errors/5162a20430cbfd59. Report an issue: GitHub.