Skip to content

Commit

Permalink
fix issue with argparser not able to show output of 'buildtest --help…
Browse files Browse the repository at this point in the history
…-all' due to name conflict.

We have fixed this now and command options are working.
Created a method in BuildTestParser called get_subcommands which will retrieve a list of subcommands that can be
used by 'buildtest commands' to show list of commands
  • Loading branch information
shahzebsiddiqui committed Feb 16, 2024
1 parent a74e2f7 commit 84f9424
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
58 changes: 27 additions & 31 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,6 @@ def __init__(self):
"commands": {"help": "List all buildtest commands", "aliases": ["cmds"]},
}

self.hidden_subcommands = {
"docs": {},
"tutorial-examples": {},
"schemadocs": {},
"unittests": {"aliases": ["test"]},
"stylecheck": {"aliases": ["style"]},
}

self.buildtest_subcommands = list(self.subcommands.keys()) + list(
self.hidden_subcommands.keys()
)

self.parser = argparse.ArgumentParser(
prog=self._progname,
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand All @@ -307,15 +295,37 @@ def __init__(self):
)

self._build_options()
self._build_subparsers()

# list used to store all main options for buildtest
self.main_options = self.get_buildtest_options()

self.hidden_subcommands = {
"docs": {},
"tutorial-examples": {},
"unittests": {"aliases": ["test"]},
"stylecheck": {"aliases": ["style"]},
}

# Variables needed to show all sub commands and their help message
show_all_help = any(arg in ["-H", "--help-all"] for arg in sys.argv)
if show_all_help:
self.help_all()
self.hidden_subcommands = {
"tutorial-examples": {
"help": "Generate documentation examples for Buildtest Tutorial"
},
"docs": {"help": "Open buildtest docs in browser"},
"unittests": {"help": "Run buildtest unit tests", "aliases": ["test"]},
"stylecheck": {
"help": "Run buildtest style checks",
"aliases": ["style"],
},
}

self.buildtest_subcommands = list(self.subcommands.keys()) + list(
self.hidden_subcommands.keys()
)

self._build_subparsers()

self.build_menu()
self.buildspec_menu()
Expand Down Expand Up @@ -435,23 +445,9 @@ def get_buildtest_options(self):
main_options.add("--help")
return list(sorted(main_options))

def help_all(self):
"""This method will add parser for hidden command that can be shown when using ``--help-all/-H``"""

hidden_parser = {
"tutorial-examples": {
"help": "Generate documentation examples for Buildtest Tutorial"
},
"docs": {"help": "Open buildtest docs in browser"},
"schemadocs": {"help": "Open buildtest schema docs in browser"},
"unittests": {"help": "Run buildtest unit tests", "aliases": ["test"]},
"stylecheck": {"help": "Run buildtest style checks", "aliases": ["style"]},
}

for name, subcommand in hidden_parser.items():
self.subparsers.add_parser(
name, help=subcommand["help"], aliases=subcommand.get("aliases", [])
)
def get_subcommands(self):
"""Return a list of buildtest commands. This is useful for ``buildtest commands`` command to show a list of buildtest commands"""
return list(self.subcommands.keys()) + list(self.hidden_subcommands.keys())

def get_parent_parser(self):
parent_parser = {}
Expand Down
2 changes: 1 addition & 1 deletion buildtest/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def list_buildtest_commands(with_aliases=None):
"""

cmds = BuildTestParser()
subcmds = sorted(cmds.buildtest_subcommands)
subcmds = sorted(cmds.get_subcommands())

# if --with-aliases we will show all available choices for subcommands including aliases
if with_aliases:
Expand Down

0 comments on commit 84f9424

Please sign in to comment.