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

Add option "add_help=False" when creating an ArgumentParser object. #1083

Open
PelleEikeberg opened this issue Dec 12, 2024 · 2 comments
Open

Comments

@PelleEikeberg
Copy link

PelleEikeberg commented Dec 12, 2024

Right now there is no option for creating an ArgumentParser object without the help option. ArgumentParser() allows for the add_help=False option. Adding this option to the init of VUnitCLI would allow us to then use the resulting ArgumentParser object as a parent of other ArgumentParser() commands.

The argument for this is when I want to have Vunit as part of a larger script, and therefore add other options to the --help tag.

Changing the lines (line 44-82 in vunit_cli.py) to add this would be simple and only add usability.

class VUnitCLI(object):
    """
    VUnit command line interface
    """

    def __init__(self, description=None, add_help_descr=True):
        """
        :param description: A custom short description of the command line tool
        """
        self.parser = _create_argument_parser(description, add_help_descr=add_help_descr)
        self.add_help_descr = add_help_descr

    def parse_args(self, argv=None):
        """
        Parse command line arguments

        :param argv: Use explicit argv instead of actual command line argument
        :returns: The parsed argument namespace object
        """
        return self.parser.parse_args(args=argv)


def _create_argument_parser(description=None, for_documentation=False, add_help_descr=True):
    """
    Create the argument parser

    :param description: A custom short description of the command line tool
    :param for_documentation: When used for user guide documentation
    :returns: The created :mod:`argparse` parser object
    """
    if description is None:
        description = f"VUnit command line tool version {version()!s}"

    if for_documentation:
        default_output_path = "./vunit_out"
    else:
        default_output_path = str(Path(os.getcwd()).resolve() / "vunit_out")

    parser = argparse.ArgumentParser(description=description, add_help=add_help_descr)
@PelleEikeberg
Copy link
Author

I tried to create a branch for pull-request, but it seems I don't have access to do this. I might be new to Git Hub and therefore missing some obvious way, but all the code requiring change is in the example code above.

@LarsAsplund
Copy link
Collaborator

To create a PR you will have to fork the VUnit project first, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo

Regarding your use case. Have you looked at https://vunit.github.io/py/ui.html#adding-custom-command-line-arguments? That is how you would add custom options to the existing ones.

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

No branches or pull requests

2 participants