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" "-V" "-H")
Mendi03 marked this conversation as resolved.
Show resolved Hide resolved

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
54 changes: 42 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,11 @@
from buildtest.defaults import console
from buildtest.schemas.defaults import schema_table

# Variables needed to show all sub commands and their help mesaage
help1 = "-H" in sys.argv
help2 = "--help-all" in sys.argv
show_all_help = help1 or help2
Mendi03 marked this conversation as resolved.
Show resolved Hide resolved


def build_filters_format(val):
"""This method is used as validate argument type for ``buildtest build --filter``.
Expand Down Expand Up @@ -260,6 +266,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="Show help for all commands", action="help"
Mendi03 marked this conversation as resolved.
Show resolved Hide resolved
)

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

Expand Down Expand Up @@ -353,8 +362,16 @@
"-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")
# Subcommands that do not need to be shown in --help
if show_all_help:
subparsers.add_parser(

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

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L367

Added line #L367 was not covered by tests
"schemadocs", help="Open buildtest schema docs in browser"
)
subparsers.add_parser("docs", help="Open buildtest docs in browser")

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

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L370

Added line #L370 was not covered by tests
else:
subparsers.add_parser("schemadocs")
subparsers.add_parser("docs")
shahzebsiddiqui marked this conversation as resolved.
Show resolved Hide resolved

subparsers.add_parser(
"debugreport",
help="Display system information and additional information for debugging purposes.",
Expand Down Expand Up @@ -405,9 +422,13 @@
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
if show_all_help:
stylecheck_parser = subparsers.add_parser(

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

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L427

Added line #L427 was not covered by tests
"stylecheck", aliases=["style"], help="Run buildtest style checks"
)
else:
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 +451,14 @@
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
if show_all_help:
unittests_parser = subparsers.add_parser(

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

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L456

Added line #L456 was not covered by tests
"unittests", help="Run buildtest unit tests", aliases=["test"]
)
else:
unittests_parser = subparsers.add_parser("unittests", aliases=["test"])

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

subparsers.add_parser(
"tutorial-examples",
help="Generate documentation examples for Buildtest Tutorial",
)
# Subcommands that do not need to be shown in --help
if show_all_help:
subparsers.add_parser(

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

View check run for this annotation

Codecov / codecov/patch

buildtest/cli/__init__.py#L489

Added line #L489 was not covered by tests
"tutorial-examples",
help="Generate documentation examples for Buildtest Tutorial",
)
else:
subparsers.add_parser("tutorial-examples")


def path_menu(subparsers):
Expand Down
Loading