Skip to content

feat: add variadic argument support to CLI targets#2

Open
rfhold wants to merge 3 commits intomasterfrom
rfh/var-args
Open

feat: add variadic argument support to CLI targets#2
rfhold wants to merge 3 commits intomasterfrom
rfh/var-args

Conversation

@rfhold
Copy link
Copy Markdown

@rfhold rfhold commented Mar 30, 2026

Extends mage target invocation to support variadic parameters (e.g. func Deploy(env string, flags ...string)). Previously such functions were silently skipped by the parser.

  • parse/parse.go: detect *ast.Ellipsis in funcType(), add IsVariadic to Function, generate slice-consuming code in ExecCode()
  • mage/template.go: use len(Args)-1 minimum arg count for variadic targets; conditionalize error message wording
  • Tests: Greet(...string) and Tag(string, ...string) testdata targets; five new integration tests

mg.F() variadic support (added in magefile#402) is unaffected.

rfhold added 3 commits March 27, 2026 18:04
Detect *ast.Ellipsis in funcType() to accept variadic parameters as
targets. Add IsVariadic to Function struct. ExecCode() generates
slice-consuming code for the variadic arg and spreads it at the call site.
Use IsVariadic on Function to compute a minimum arg count (len(Args)-1)
instead of an exact count, allowing the variadic slice to be empty.
Error messages distinguish 'expected at least N' for variadic targets.
Add Greet(...string) and Tag(string, ...string) to the args testdata
magefile. Add five integration tests covering zero variadic args, one
arg, multiple args, missing required prefix, and mixed required+variadic.
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.

1 participant