Skip to content

support variadic target arguments - #557

Open
younggglcy wants to merge 3 commits into
magefile:masterfrom
younggglcy:codex/variadic-args
Open

support variadic target arguments#557
younggglcy wants to merge 3 commits into
magefile:masterfrom
younggglcy:codex/variadic-args

Conversation

@younggglcy

Copy link
Copy Markdown

Closes #340.

What this changes

Mage now discovers exported targets whose final parameter is ...string and
passes the remaining command-line tokens to it unchanged. A variadic target is
terminal for the invocation, so existing fixed-arity target chaining keeps its
current behavior and Mage does not need to guess boundaries from target names.

Pointer-style optional arguments may precede the variadic tail. In that form,
Mage parses flags until the first non-option token; a target-local -- can be
used when the tail itself starts with -. This separator is intentionally
scoped to optional-plus-variadic targets: pure variadic targets still receive
-- literally, and non-variadic target behavior is unchanged.

The parser metadata is shared by generated dispatch and help output, and the
website documentation describes the same terminal-target and pass-through
semantics. Unsupported non-string variadics remain hidden. Alias conflicts are
reported only when this feature makes a variadic target newly discoverable, so
historical fixed-arity alias behavior is preserved.

Example

func Run(name string, verbose *bool, args ...string) error {
	// ...
	return nil
}
mage run worker -verbose -- -race ./...

Validation

  • go test -vet=all -tags CI -race ./...
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.2 run
  • Go 1.18.10 coverage for the parser and variadic dispatch tests

@younggglcy
younggglcy marked this pull request as ready for review August 12, 2026 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to get variadic arguments

1 participant