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

Modified behavior of --help/-h and added commands -H/--help--all #1568

Merged
merged 13 commits into from
Jul 27, 2023
6 changes: 3 additions & 3 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ _buildtest ()

COMPREPLY=() # Array variable storing the possible completions.

declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-V")
declare -a buildtest_opts=("--color" "--config" "--debug" "--editor" "--help" "--helpcolor" "--help-all" "--logpath" "--loglevel" "--print-log" "--no-color" "--report" "--version" "--view-log" "-c" "-d" "-h" "-l" "-p" "-r" "-H" "-V")

commands_with_input=( "--color" "--config" "-c" "--report" "-r" "--loglevel" "-l" "--editor" ) # Array variable storing commands which require an input argument from the user.

Expand Down Expand Up @@ -200,7 +200,7 @@ _buildtest ()
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
;;
path)
local opts="-b -be -e -h -o -s -t --buildscript --buildenv --errfile --help --outfile --stagedir --testpath"
local opts="-b -be -e -h -o -s -t --buildscript --buildenv --errfile --help --outfile --stagedir --testpath"
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
COMPREPLY=( $( compgen -W "$opts" -- $cur ) )
Expand Down Expand Up @@ -458,7 +458,7 @@ _buildtest ()
*)
local cmds="build buildspec cd cdash clean config debugreport docs help info inspect history path report schema schemadocs stats stylecheck tutorial-examples unittests"
local alias_cmds="bd bc cg debug it h hy rt style test"
local opts="--color --config --debug --editor --help --helpcolor --logpath --loglevel --print-log --no-color --report --version --view-log -c -d -h -l -p -r -V"
local opts="--color --config --debug --editor --help --helpcolor --help-all --logpath --loglevel --print-log --no-color --report --version --view-log -c -d -h -l -p -r -H -V"

case "${cur}" in
# print main options to buildtest
Expand Down
56 changes: 44 additions & 12 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import argparse
import datetime
import sys

from pygments.styles import STYLE_MAP
from rich.color import Color, ColorParseError
Expand All @@ -12,6 +13,9 @@
from buildtest.defaults import console
from buildtest.schemas.defaults import schema_table

# Variables needed to show all sub commands and their help mesaage
show_all_help = "-H" in sys.argv or "--help-all" in sys.argv


def build_filters_format(val):
"""This method is used as validate argument type for ``buildtest build --filter``.
Expand Down Expand Up @@ -260,6 +264,9 @@
help="Print available color options in a table format.",
)
parser.add_argument("-r", "--report", help="Specify path to test report file")
parser.add_argument(
"-H", "--help-all", help="List all commands and options", action="help"
)

subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")

Expand Down Expand Up @@ -328,6 +335,10 @@
misc_menu(subparsers)
tutorial_examples_menu(subparsers)

# Displays all hidden comands
if show_all_help:
help_all(subparsers)

Check warning on line 340 in buildtest/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L340

Added line #L340 was not covered by tests

return parser


Expand All @@ -338,6 +349,10 @@
subparsers (argparse._SubParsersAction): Subparser object to add subparser
"""

# Subcommands that do not need to be shown in ``--help``
subparsers.add_parser("docs")
subparsers.add_parser("schemadocs")

cd_parser = subparsers.add_parser(
"cd", help="change directory to root of test given a test name"
)
Expand All @@ -353,8 +368,6 @@
"-y", "--yes", action="store_true", help="Confirm yes for all prompts"
)

subparsers.add_parser("docs", help="Open buildtest docs in browser")
subparsers.add_parser("schemadocs", help="Open buildtest schema docs in browser")
subparsers.add_parser(
"debugreport",
help="Display system information and additional information for debugging purposes.",
Expand Down Expand Up @@ -405,9 +418,8 @@
subparsers (argparse._SubParsersAction): Subparser object to add subparser
"""

stylecheck_parser = subparsers.add_parser(
"stylecheck", aliases=["style"], help="Run buildtest style checks"
)
# Subcommands that do not need to be shown in ``--help``
stylecheck_parser = subparsers.add_parser("stylecheck", aliases=["style"])

stylecheck_parser.add_argument(
"--no-black", action="store_true", help="Don't run black style check"
Expand All @@ -430,9 +442,9 @@
subparsers (argparse._SubParsersAction): Subparser object to add subparser
"""

unittests_parser = subparsers.add_parser(
"unittests", help="Run buildtest unit tests", aliases=["test"]
)
# Subcommands that do not need to be shown in --help
unittests_parser = subparsers.add_parser("unittests", aliases=["test"])

unittests_parser.add_argument(
"-c",
"--coverage",
Expand All @@ -458,10 +470,7 @@
subparsers (argparse._SubParsersAction): Subparser object to add subparser
"""

subparsers.add_parser(
"tutorial-examples",
help="Generate documentation examples for Buildtest Tutorial",
)
subparsers.add_parser("tutorial-examples")


def path_menu(subparsers):
Expand Down Expand Up @@ -1295,3 +1304,26 @@
upload.add_argument(
"-o", "--open", action="store_true", help="Open CDASH report in browser"
)


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

Args:
subparsers (argparse._SubParsersAction): Subparser object
"""
hidden_parser = {

Check warning on line 1315 in buildtest/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L1315

Added line #L1315 was not covered by tests
"tutorial-examples": "Generate documentation examples for Buildtest Tutorial",
"docs": "Open buildtest docs in browser",
"schemadocs": "Open buildtest schema docs in browser",
"unittests": {"help": "Run buildtest unit tests", "aliases": ["test"]},
"stylecheck": {"help": "Run buildtest style checks", "aliases": ["style"]},
}

for command, val in hidden_parser.items():
if type(val) is dict:
subparsers.add_parser(

Check warning on line 1325 in buildtest/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L1323-L1325

Added lines #L1323 - L1325 were not covered by tests
command, help=val.get("help"), aliases=val.get("aliases")
)
else:
subparsers.add_parser(command, help=val)

Check warning on line 1329 in buildtest/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L1329

Added line #L1329 was not covered by tests
Loading