Skip to content

Add support for optional arguments#538

Merged
natefinch merged 8 commits intomasterfrom
nf/opt
Mar 8, 2026
Merged

Add support for optional arguments#538
natefinch merged 8 commits intomasterfrom
nf/opt

Conversation

@natefinch
Copy link
Member

This update adds support for optional arguments, which are indicated in the go code by pointer arguments. In the CLI, you must use -arg=value semantics to specify optional values (or just -arg if the argument is a boolean and you want to specify true).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds “optional argument” support to mage targets by treating pointer-typed parameters as optional and parsing them from -name=value flags, with corresponding updates to help/usage output and new test coverage.

Changes:

  • Extend parse metadata to mark pointer parameters as optional and generate execution code that parses -name=value options into pointer variables.
  • Update generated help/usage to show required args positionally and optional args in bracketed [-name=<type>] form.
  • Add parse- and invocation-level tests plus test magefiles/testdata demonstrating optional arguments across supported types.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
site/content/targets/_index.en.md Documents optional arguments via pointer params and -name=value CLI syntax.
parse/testdata/optargs.go New parse testdata covering optional args across supported base types.
parse/parse_test.go Adds unit test asserting optional args are detected and typed correctly.
parse/parse.go Adds Arg.Optional and generates optional-arg parsing code + usage helpers (Required/Optional args).
magefile.go Removes previously defined alias/target sample code from repo magefile.
mage/testdata/optargs/magefile.go New runtime test magefile demonstrating optional args and chaining behavior.
mage/template.go Updates help output and required-arg counting to account for optional args.
mage/args_test.go Adds end-to-end tests for optional args parsing, errors, chaining, and help output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@natefinch natefinch merged commit 69e6f82 into master Mar 8, 2026
28 of 29 checks passed
@natefinch natefinch deleted the nf/opt branch March 8, 2026 00:51
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.

2 participants