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 command aliases for several buildtest commands #1233

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ _buildtest ()
;;

report|rt)
local opts="--color --end --failure --filter --format --help --helpfilter --helpformat --latest --no-header --oldest --pager --passed --start --terse -e -f -h -n -p -s -t clear list summary"
local opts="--color --end --failure --filter --format --help --helpfilter --helpformat --latest --no-header --oldest --pager --passed --start --terse -e -f -h -n -p -s -t c clear l list sm summary"
local copts=$(python -c "from rich.color import ANSI_COLOR_NAMES;print(' '.join(list(ANSI_COLOR_NAMES.keys())))")
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
case ${prev} in --color)
Expand All @@ -180,26 +180,26 @@ _buildtest ()
;;

config|cg)
local cmds="-h --help compilers edit executors path systems validate view"
local cmds="-h --help co compilers e edit ex executors p path systems validate v view"

COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )
# handle completion logic for 'buildtest config <subcommand>' based on subcommands
case "${COMP_WORDS[2]}" in
compilers)
compilers|co)
local opts="--help --json --yaml -h -j -y find test"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
if [[ "${prev}" == "find" ]]; then
local opts="--detailed --help --modulepath --update -d -h -m -u"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
executors)
executors|ex)
local opts="--help --disabled --invalid --json --yaml -d -h -i -j -y"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
validate|systems)
local opts="-h --help"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
view)
view|v)
local opts="--help --pager --theme -h -p -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )

Expand All @@ -211,32 +211,32 @@ _buildtest ()
esac
;;
inspect|it)
local cmds="--help -h buildspec list name query"
local cmds="--help -h b buildspec l list n name q query"

COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )

# case statement to handle completion for buildtest inspect [name|id|list] command
case "${COMP_WORDS[2]}" in
list)
list|l)
local opts="--builder --help --no-header --terse -b -h -n -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
name)
name|n)
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )

if [[ $cur == -* ]] ; then
local opts="--all --help -a -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
buildspec)
buildspec|b)
COMPREPLY=( $( compgen -W "$(_test_buildspec)" -- $cur ) )

if [[ $cur == -* ]] ; then
local opts="--all --help -a -h"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
fi
;;
query)
query|q)
COMPREPLY=( $( compgen -W "$(_builder_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
local opts="--buildscript --buildenv --error --help --output --testpath -b -be -e -o -h -o -t"
Expand All @@ -247,7 +247,7 @@ _buildtest ()
;;

buildspec|bc)
local cmds="-h --help edit-test edit-file find maintainers show show-fail summary validate"
local cmds="-h --help ef edit-file et edit-test f find maintainers s show sf show-fail sm summary val validate"
COMPREPLY=( $( compgen -W "${cmds}" -- $cur ) )

# switch based on 2nd word 'buildtest buildspec <subcommand>'
Expand All @@ -267,7 +267,7 @@ _buildtest ()
COMPREPLY=( $( compgen -W "${allopts}" -- $cur ) );;
esac
;;
summary)
summary|sm)
case ${COMP_WORDS[3]} in
# completion for rest of arguments
*)
Expand All @@ -277,10 +277,11 @@ _buildtest ()
COMPREPLY=( $( compgen -W "${allopts}" -- $cur ) );;
esac
;;

edit-test)
edit-file|ef)
COMPREPLY=( $( compgen -W "$(_avail_buildspecs)" -- $cur ) );;
edit-test|et)
COMPREPLY=( $( compgen -W "$(_buildspec_cache_test_names)" -- $cur ) );;
show)
show|s)
local opts="-h --help --theme"
COMPREPLY=( $( compgen -W "$(_buildspec_cache_test_names)" -- $cur ) )
if [[ $cur == -* ]] ; then
Expand All @@ -292,7 +293,7 @@ _buildtest ()
return
esac
;;
show-fail)
show-fail|sf)
local opts="-h --help --theme"
COMPREPLY=( $( compgen -W "$(_failed_tests)" -- $cur ) )
if [[ $cur == -* ]] ; then
Expand All @@ -303,7 +304,7 @@ _buildtest ()
return
esac
;;
maintainers)
maintainers|m)
local opts="--breakdown --list --help --terse --no-header -b -h -l -n find"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )

Expand All @@ -312,10 +313,7 @@ _buildtest ()
COMPREPLY=( $( compgen -W "$(_avail_maintainers)" -- $cur ) );;
esac
;;

edit-file)
COMPREPLY=( $( compgen -W "$(_avail_buildspecs)" -- $cur ) );;
validate)
validate|val)
local opts="--buildspec --exclude --executor --tag -b -e -t -x "

COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
Expand Down
54 changes: 34 additions & 20 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def buildspec_menu(subparsers):

# buildtest buildspec edit-file
edit_via_filename = subparsers_buildspec.add_parser(
"edit-file", help="Edit buildspec file based on filename"
"edit-file", aliases=["ef"], help="Edit buildspec file based on filename"
)
edit_via_filename.add_argument(
"file",
Expand All @@ -588,7 +588,7 @@ def buildspec_menu(subparsers):

# buildtest buildspec edit-test
edit_via_testname = subparsers_buildspec.add_parser(
"edit-test", help="Edit buildspec file based on test name"
"edit-test", aliases=["et"], help="Edit buildspec file based on test name"
)
edit_via_testname.add_argument(
"name",
Expand All @@ -599,12 +599,12 @@ def buildspec_menu(subparsers):
# buildtest buildspec find

buildspec_find = subparsers_buildspec.add_parser(
"find", help="Query information from buildspecs cache"
"find", aliases=["f"], help="Query information from buildspecs cache"
)

# buildtest buildspec maintainers
buildspec_maintainers = subparsers_buildspec.add_parser(
"maintainers", help="Query maintainers from buildspecs cache"
"maintainers", aliases=["m"], help="Query maintainers from buildspecs cache"
)

subparsers_maintainers = buildspec_maintainers.add_subparsers()
Expand Down Expand Up @@ -741,7 +741,7 @@ def buildspec_menu(subparsers):

# buildtest buildspec show
show_buildspecs = subparsers_buildspec.add_parser(
"show", help="Show content of buildspec file"
"show", aliases=["s"], help="Show content of buildspec file"
)
show_buildspecs.add_argument(
"name",
Expand All @@ -757,7 +757,9 @@ def buildspec_menu(subparsers):
)
# buildtest buildspec show-fail
show_fail_buildspecs = subparsers_buildspec.add_parser(
"show-fail", help="Show content of buildspec file for all failed tests"
"show-fail",
aliases=["sf"],
help="Show content of buildspec file for all failed tests",
)
show_fail_buildspecs.add_argument(
"name",
Expand All @@ -774,15 +776,15 @@ def buildspec_menu(subparsers):

# buildtest buildspec summary
buildspec_summary = subparsers_buildspec.add_parser(
"summary", help="Print summary of buildspec cache"
"summary", aliases=["sm"], help="Print summary of buildspec cache"
)
# buildtest buildspec summary options
buildspec_summary.add_argument(
"-p", "--pager", action="store_true", help="Enable PAGING when viewing result"
)
# buildtest buildspec validate
buildspec_validate = subparsers_buildspec.add_parser(
"validate", help="Validate buildspecs with JSON Schema"
"validate", aliases=["val"], help="Validate buildspecs with JSON Schema"
)
# buildtest buildspec validate options
buildspec_validate.add_argument(
Expand Down Expand Up @@ -830,22 +832,30 @@ def config_menu(subparsers):
metavar="",
)

compilers = subparsers_config.add_parser("compilers", help="Search compilers")
compilers = subparsers_config.add_parser(
"compilers", aliases=["co"], help="Search compilers"
)

subparsers_config.add_parser("edit", help="Open configuration file in editor")
subparsers_config.add_parser(
"edit", aliases=["e"], help="Open configuration file in editor"
)

executors = subparsers_config.add_parser(
"executors", help="Query executors from buildtest configuration"
"executors", aliases=["ex"], help="Query executors from buildtest configuration"
)

subparsers_config.add_parser("path", help="Show path to configuration file")
subparsers_config.add_parser(
"path", aliases=["p"], help="Show path to configuration file"
)

subparsers_config.add_parser("systems", help="List all available systems")

subparsers_config.add_parser(
"validate", help="Validate buildtest settings file with schema."
)
view_parser = subparsers_config.add_parser("view", help="View configuration file")
view_parser = subparsers_config.add_parser(
"view", aliases=["v"], help="View configuration file"
)
view_parser.add_argument(
"-t",
"--theme",
Expand Down Expand Up @@ -933,10 +943,10 @@ def report_menu(subparsers):
metavar="",
dest="report_subcommand",
)
subparsers.add_parser("clear", help="Remove all report file")
subparsers.add_parser("list", help="List all report files")
subparsers.add_parser("clear", aliases=["c"], help="Remove all report file")
subparsers.add_parser("list", aliases=["l"], help="List all report files")
parser_report_summary = subparsers.add_parser(
"summary", help="Summarize test report"
"summary", aliases=["sm"], help="Summarize test report"
)

# buildtest report
Expand Down Expand Up @@ -1040,10 +1050,12 @@ def inspect_menu(subparsers):
metavar="",
)
inspect_buildspec = subparser.add_parser(
"buildspec", help="Inspect a test based on buildspec"
"buildspec", aliases=["b"], help="Inspect a test based on buildspec"
)
name = subparser.add_parser("name", aliases=["n"], help="Specify name of test")
query_list = subparser.add_parser(
"query", aliases=["q"], help="Query fields from record"
)
name = subparser.add_parser("name", help="Specify name of test")
query_list = subparser.add_parser("query", help="Query fields from record")

# buildtest inspect buildspec
inspect_buildspec.add_argument(
Expand All @@ -1057,7 +1069,9 @@ def inspect_menu(subparsers):

# buildtest inspect list
inspect_list = subparser.add_parser(
"list", help="List all test names, ids, and corresponding buildspecs"
"list",
aliases=["l"],
help="List all test names, ids, and corresponding buildspecs",
)
inspect_list.add_argument(
"-n",
Expand Down
8 changes: 4 additions & 4 deletions buildtest/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def config_cmd(args, configuration, editor):
args (dict): Parsed arguments from `ArgumentParser.parse_args <https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args>`_
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
"""
if args.config == "view":
if args.config in ["view", "v"]:
view_configuration(configuration, theme=args.theme, pager=args.pager)

elif args.config == "executors":
elif args.config in ["executors", "ex"]:
buildexecutor = BuildExecutor(configuration)
view_executors(
configuration,
Expand All @@ -38,10 +38,10 @@ def config_cmd(args, configuration, editor):
elif args.config == "systems":
view_system(configuration)

elif args.config == "edit":
elif args.config in ["edit", "e"]:
edit_configuration(configuration, editor)

elif args.config == "path":
elif args.config in ["path", "p"]:
view_path(configuration)


Expand Down
8 changes: 4 additions & 4 deletions buildtest/cli/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ def inspect_cmd(args, report_file=None):
report = Report(report_file)

# implements command 'buildtest inspect list'
if args.inspect == "list":
if args.inspect in ["list", "l"]:
inspect_list(
report, terse=args.terse, header=args.no_header, builder=args.builder
)
return

# implements command 'buildtest inspect name'
if args.inspect == "name":
if args.inspect in ["name", "n"]:
inspect_by_name(report, args.name)
return

if args.inspect == "query":
if args.inspect in ["query", "q"]:
inspect_query(report, args)
return

if args.inspect == "buildspec":
if args.inspect in ["buildspec", "b"]:
inspect_buildspec(report, input_buildspecs=args.buildspec, all_records=args.all)


Expand Down
6 changes: 3 additions & 3 deletions buildtest/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def report_cmd(args, report_file=None):
"""Entry point for ``buildtest report`` command"""
consoleColor = checkColor(args.color)

if args.report_subcommand == "clear":
if args.report_subcommand in ["clear", "c"]:
# if BUILDTEST_REPORTS file is not present then we have no report files to delete since it tracks all report files that are created
if not is_file(BUILDTEST_REPORTS):
sys.exit("There is no report file to delete")
Expand All @@ -779,7 +779,7 @@ def report_cmd(args, report_file=None):
os.remove(BUILDTEST_REPORTS)
return

if args.report_subcommand == "list":
if args.report_subcommand in ["list", "l"]:
if not is_file(BUILDTEST_REPORTS):
sys.exit(
console.print(
Expand All @@ -804,7 +804,7 @@ def report_cmd(args, report_file=None):
report_file=report_file,
count=args.count,
)
if args.report_subcommand == "summary":
if args.report_subcommand in ["summary", "sm"]:
if args.pager:
with console.pager():
report_summary(results, detailed=args.detailed, color=consoleColor)
Expand Down
Loading