Skip to content

Add help parameter to arguments#3473

Open
yurishevtsov wants to merge 1 commit into
pallets:mainfrom
yurishevtsov:add-help-kwarg-to-arg-params
Open

Add help parameter to arguments#3473
yurishevtsov wants to merge 1 commit into
pallets:mainfrom
yurishevtsov:add-help-kwarg-to-arg-params

Conversation

@yurishevtsov
Copy link
Copy Markdown
Contributor

@yurishevtsov yurishevtsov commented May 19, 2026

Adds a help parameter to click.argument() and an Arguments section on --help when argument help is set. Commands without argument help are unchanged.

Implementation follows options: Argument.get_help_record() returns the metavar and help text for the help formatter (the base Parameter class returns None, so arguments never appeared in help tables before).

Argument.to_info_dict() now includes help, matching Option, so parameter metadata stays consistent for doc tools; this is not required for CLI help output.

Deprecated arguments without explicit help show a deprecation-only row in Arguments, matching deprecated options.

fixes #2983

@yurishevtsov yurishevtsov force-pushed the add-help-kwarg-to-arg-params branch 4 times, most recently from 73e3c13 to b145f91 Compare May 19, 2026 18:55
@Rowlando13 Rowlando13 added the f:help feature: help text label May 19, 2026
@Rowlando13 Rowlando13 modified the milestones: 9.0.0, 8.5.0 May 19, 2026
Refactor: pull out args formatter into a dedicated method
@yurishevtsov yurishevtsov force-pushed the add-help-kwarg-to-arg-params branch from b145f91 to 71240f8 Compare May 19, 2026 20:02
@kdeldycke
Copy link
Copy Markdown
Collaborator

That feature exists in Cloup since v0.1.40: https://github.com/janluke/cloup/releases/tag/v0.14.0 . So additional review from @janluke would be great! :)

@kdeldycke kdeldycke requested a review from janluke May 23, 2026 12:42
@kdeldycke kdeldycke added the f:parameters feature: input parameter types label May 23, 2026
Copy link
Copy Markdown
Collaborator

@kdeldycke kdeldycke left a comment

Choose a reason for hiding this comment

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

Good PR that mirrors the way help is managed on Option.

Comment thread CHANGES.rst
Unreleased

- :class:`Argument` accepts a ``help`` parameter, and help output includes
an ``Arguments`` section when argument help is available. :issue:`2983`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
an ``Arguments`` section when argument help is available. :issue:`2983`
an ``Arguments`` section when argument help is available. :issue:`2983` :pr:`3473`

Comment thread src/click/core.py

if deprecated:
label = _format_deprecated_label(deprecated)
help = f"{help} {label}" if help is not None else label
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you extend the test_deprecated_usage test so we cover the look and shape of the deprecation message for the argument?

Comment thread src/click/core.py
formatter.write_dl(opts)

def format_args(self, ctx: Context, formatter: HelpFormatter) -> None:
"""Writes all the arguments into the formatter if they exist."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe update that docstring as that method only write arguments that produce a help record.

Comment thread src/click/core.py

super().__init__(param_decls, required=required, **attrs)

def to_info_dict(self) -> dict[str, t.Any]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add a test that cover this new public method?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And also use that oportunity to check the behavior with None, empty help, and multi-line help. With single and multiple arguments. And with nargs=-1 arguments.

Comment thread src/click/core.py
with formatter.section(_("Options")):
formatter.write_dl(opts)

def format_args(self, ctx: Context, formatter: HelpFormatter) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we name that format_arguments to align it with the other format_options, format_epilog and format_usage which use long names?

Comment thread docs/documentation.md
{class}`click.argument` does not take a `help` parameter. This follows the Unix Command Line Tools convention of using arguments only for necessary things and documenting them in the command help text
by name. This should then be done via the docstring.
{class}`click.argument` accepts an optional `help` parameter that is shown in
the ``Arguments`` section of the help page. You can still document arguments
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A detailed I noticed: Cloup use Positional arguments for its section name while this use Arguments.

See: https://github.com/janluke/cloup/blob/d53d04f51846e3dbfe6a1b97ad677bfc5cdda47f/docs/pages/arguments.rst?plain=1#L48

Not sure which is strictly right. @janluke any opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f:help feature: help text f:parameters feature: input parameter types

Projects

None yet

3 participants