Skip to content

With invoke_without_command set, commands are not marked as optionalย #3059

Description

@andreynovikov

Having

@click.group(invoke_without_command=True)
def main():
    if ctx.invoked_subcommand is not None:
        return
    # do something by default

I expect --help to output:

Usage: app.py [OPTIONS] [COMMAND] [ARGS]...

But it outputs:

Usage: app.py [OPTIONS] COMMAND [ARGS]...

Environment:

  • Python version: 3.11.8
  • Click version: 8.2.0

Activity

  1. Rowlando13 commented on Sep 14, 2025

    @Rowlando13
    Member

    Interesting idea. I am not sure how consistent Click is in its marking optional with brackets in the help pages. I will have to take a look.

  2. deleted a comment from siddmoparti on Mar 20, 2026
  3. Rowlando13 commented on May 19, 2026

    @Rowlando13
    Member

    Current help pages are reasonable. In the short term, a lot of effort effort is needs to go to making our api less public in a way that is reasonable to users. So closing for now.

  4. kdeldycke commented on May 22, 2026

    @kdeldycke
    Collaborator

    @Rowlando13 to be honest I like the visual hint that command is optional. And looks like we have an easy PR in line at #3271 that I can take over.

    I'm in favor of re-opening this issue.

  5. added this to the 8.4.2 milestone on May 22, 2026
  6. changed the title [-]With invoke_without_command set commands are not marked as optional[/-] [+]With `invoke_without_command` set, commands are not marked as optional[/+] on May 22, 2026
  7. Rowlando13 commented on May 23, 2026

    @Rowlando13
    Member

    If you are interested, then by all means!

  8. kdeldycke commented on May 23, 2026

    @kdeldycke
    Collaborator

    If you are interested, then by all means!

    Went down the rabbit hole yesterday and found out that the bracket syntax is a convention described in POSIX for optional argument and operands. There is no subcommand concept in POSIX, so a subcommand in the context of Click can be considered as an operand as it is positioned after the CLI invokation. So yes, we should use [COMMAND] in this case.

  9. added 2 commits that reference this issue on May 23, 2026
    0d62e12
    665736b
  10. kdeldycke commented on May 27, 2026

    @kdeldycke
    Collaborator

    This has been fixed by: #3507

  11. locked as resolved and limited conversation to collaborators on Jul 24, 2026
  12. added
    parsingParsing, parameters, commands, chaining, context
    and removed on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help outputHelp text formatting, layout, and --help renderingparsingParsing, parameters, commands, chaining, context

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions