go-task/task · error

task: --nested only applies to --json with --list or --list-

Error message

task: --nested only applies to --json with --list or --list-all

What it means

Task CLI validates flag combinations in internal/flags.Validate. The --nested flag is only meaningful when machine-readable output is enabled, so it is rejected unless --json is combined with --list or --list-all.

Source

Thrown at internal/flags/flags.go:241

		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")
	}

	if ListJson && !List && !ListAll {
		return errors.New("task: --json only applies to --list or --list-all")
	}

	if NoStatus && !ListJson {
		return errors.New("task: --no-status only applies to --json with --list or --list-all")
	}

	if Nested && !ListJson {
		return errors.New("task: --nested only applies to --json with --list or --list-all")
	}

	// Validate certificate flags
	if (Cert != "" && CertKey == "") || (Cert == "" && CertKey != "") {
		return errors.New("task: --cert and --cert-key must be provided together")
	}

	return nil
}

// WithFlags is a special internal functional option that is used to pass flags
// from the CLI into any constructor that accepts functional options.
func WithFlags() task.ExecutorOption {
	return &flagsOption{}
}

type flagsOption struct{}

View on GitHub (pinned to 385e5ad92a)

Solutions

  1. Add --json together with --list or --list-all when using --nested
  2. Remove --nested if plain (non-JSON) output is intended
  3. If invoked programmatically, set ListJson=true and List/ListAll=true alongside Nested=true before Validate runs

Example fix

// before
task --nested --list
// after
task --nested --json --list
Defensive patterns

Strategy: validation

Validate before calling

if nested && !(listJSON && (list || listAll)) {
    // fix args before invoking task
    args = append(args, "--json")
    if !contains(args, "--list") && !contains(args, "--list-all") {
        args = append(args, "--list")
    }
}

Type guard

func nestedFlagsValid(nested, listJSON, list, listAll bool) bool {
    return !nested || (listJSON && (list || listAll))
}

Prevention

When it happens

Trigger: Running `task --nested` (or passing Nested=true via WithFlags) without `--json --list` or `--json --list-all`.

Common situations: Users exploring nested task display options copy a --nested example but omit --json/--list, or scripts add --nested to plain `task --list` invocations after upgrading.

Related errors


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