Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Add the -h short-hand flag for --help to verdi #5792

Merged
merged 1 commit into from
Nov 24, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Nov 22, 2022

Fixes #5790

@sphuber
Copy link
Contributor Author

sphuber commented Nov 22, 2022

Before we accept this, I want to still want to quickly check whether there currently are not commands out there that already use -h. The tests pass, but it is possible that this is not covered by the tests.

@sphuber
Copy link
Contributor Author

sphuber commented Nov 22, 2022

Ok, I checked with the script below, and there is no verdi command that has the -h flag:

import click
from aiida.cmdline.commands.cmd_verdi import verdi

def recurse_commands(ctx, command: click.Command):
    """Recursively return all subcommands that are part of ``command``.

    :param command: The click command to start with.
    :param parents: A list of strings that represent the parent commands leading up to the current command.
    :returns: A list of strings denoting the full path to the current command.
    """
    if isinstance(command, click.Group):
        for command_name in command.commands:
            yield from recurse_commands(ctx, command.get_command(ctx, command_name))
    yield command

ctx = click.Context(verdi)

for command in recurse_commands(ctx, verdi):
    for param in command.params:
        if not isinstance(param, click.Option):
            continue
        option = param
        if '-h' in option.opts:
            print(option.opts)

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.

CLI: Consider adding -h as the short-hand flag for --help
1 participant