Skip to content

Can't access help of subcommands without going through parent's prompts #295

@philipsd6

Description

@philipsd6

I have a script with subcommands that both require a username/password. I abstracted this to the parent. Here's a short example demonstrating the issue:

import click

@click.group()
@click.option('--username', default='admin', prompt=True)
@click.password_option()
def cli(username, password):
    """This is my parent description"""
    pass

@cli.command()
@click.option('--reference', help="I should be able to see this without entering a username and password.")
def subcommand(reference):
    """This is my subcommand"""
    pass

If you access the main help:

my_prog --help

It displays the help page without any prompting for username or password, as expected. However, if you try to access the help page for the subcommand:

my_prog subcommand --help

It prompts for username and password before displaying the help page of the subcommand. This makes sense, but it still isn't expected behavior by the end user. As my sample program says, I should be able to see help without entering a username and password.

What's the correct way to model my desired behavior? Do I have to move and duplicate the username and password prompt options into each of my sub commands?

Metadata

Metadata

Assignees

No one assigned

    Labels

    f:promptfeature: prompt for input

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions