Skip to content

support for inline doc comments on optional flags#549

Merged
natefinch merged 5 commits into
masterfrom
nf/flagdocs
Mar 29, 2026
Merged

support for inline doc comments on optional flags#549
natefinch merged 5 commits into
masterfrom
nf/flagdocs

Conversation

@natefinch
Copy link
Copy Markdown
Member

e.g.

// Deploy runs the build and then uploads the artifacts to the server.
// It deploys to the given environment.
func Deploy(ctx context.Context, env string, 
    version *string, // git tag for the build, defaults to the next minor build if not set 
    dryRun *bool,    // if set to true, just outputs the build artifacts 
    ) error {
    return nil
}
$ mage -h deploy
Deploy runs the build and then uploads the artifacts to the server.
It deploys to the given environment.

Usage:

	mage deploy <env> [<flags>]

Flags:

    -version=<string>  git tag for the build, defaults to the next minor build if not set
    -dryrun=<bool>     if set to true, just outputs the build artifacts

Copy link
Copy Markdown

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

This PR adds support for showing inline (trailing) parameter comments as documentation for optional flag arguments in mage -h <target> output, including a new Flags: section when appropriate.

Changes:

  • Extend parsed function argument metadata to carry an optional inline comment and render it in help output.
  • Update parsing to preserve and/or recover inline parameter comments from Go source.
  • Update docs and add tests covering multi-flag and single-flag documented help output.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
site/content/targets/_index.en.md Updates documentation to demonstrate inline flag doc comments and new help output format.
parse/testdata/optargs.go Adds a test fixture function with inline comments on optional parameters.
parse/parse_test.go Extends optional-args parsing tests to assert captured inline comments.
parse/parse.go Adds Arg.Comment, computes whether to show a Flags: section, formats flag docs, and attempts to extract inline param comments.
mage/testdata/optargs/magefile.go Adds magefile targets used by help-output tests for documented flags.
mage/template.go Updates help template to emit [<flags>] usage and optional Flags: section.
mage/args_test.go Adds assertions for new help output that includes Flags: and inline flag documentation.

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

Comment thread site/content/targets/_index.en.md Outdated
Comment thread site/content/targets/_index.en.md Outdated
Comment thread parse/parse.go Outdated
@natefinch natefinch merged commit 88c49b7 into master Mar 29, 2026
22 checks passed
@natefinch natefinch deleted the nf/flagdocs branch March 29, 2026 14:05
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