Skip to content

Commit

Permalink
Merge pull request #1277 from buildtesters/issue_1206
Browse files Browse the repository at this point in the history
Add option buildtest --helpcolor to show available color options in table format
  • Loading branch information
shahzebsiddiqui committed Oct 19, 2022
2 parents 2db95e1 + e84d5d3 commit 6939258
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ _buildtest ()
*)
local cmds="build buildspec cd cdash clean config debugreport docs help info inspect history path report schema schemadocs stats stylecheck unittests"
local alias_cmds="bd bc cg debug it h hy rt style test"
local opts="--config --debug --editor --help --logpath --print-log --no-color --report --version --view-log -c -d -h -r -V"
local opts="--config --debug --editor --help --helpcolor --logpath --print-log --no-color --report --version --view-log -c -d -h -r -V"

case "${cur}" in
# print main options to buildtest
Expand Down
5 changes: 5 additions & 0 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ def get_parser():
parser.add_argument(
"--no-color", help="Disable colored output", action="store_true"
)
parser.add_argument(
"--helpcolor",
action="store_true",
help="Print available color options in a table format.",
)
parser.add_argument("-r", "--report", help="Specify path to test report file")

subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")
Expand Down
16 changes: 16 additions & 0 deletions buildtest/cli/helpcolor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from buildtest.defaults import console
from rich.color import ANSI_COLOR_NAMES
from rich.table import Table


def print_available_colors():
"""Print the available color options in a table format on background of the color option."""
table = Table(
"Number",
"Color",
header_style="blue",
title="Available Colors",
)
for color, number in ANSI_COLOR_NAMES.items():
table.add_row(f"[black]{number}", f"[black]{color}", style="on " + color)
console.print(table)
6 changes: 6 additions & 0 deletions buildtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from buildtest.cli.config import config_cmd
from buildtest.cli.debugreport import print_debug_report
from buildtest.cli.help import buildtest_help
from buildtest.cli.helpcolor import print_available_colors
from buildtest.cli.history import build_history
from buildtest.cli.info import buildtest_info
from buildtest.cli.inspect import inspect_cmd
Expand Down Expand Up @@ -94,6 +95,11 @@ def main():

return

# print the available color options in a table format if buildtest --helpcolor is specified
if args.helpcolor:
print_available_colors()
return

# print full path to the lastlog file if buildtest --logpath is specified
if args.logpath:
console.print(BUILDTEST_LOGFILE)
Expand Down
11 changes: 10 additions & 1 deletion docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ To access `schema docs <https://buildtesters.github.io/buildtest>`_ you can run:

buildtest schemadocs

Listing available color options (``buildtest --helpcolor``)
-------------------------------------------------------------

The ``buildtest --helpcolor`` command can be used to list the available color options in a tabular format which can be used with the `--color` option to select a color when printing table entries from several buildtest commands. This option will list all the colors printed in the background for the specified color

.. dropdown:: ``buildtest --helpcolor``

.. command-output:: buildtest --helpcolor

Disabling Colored Output
--------------------------

Expand Down Expand Up @@ -422,4 +431,4 @@ or short option (``-e``), which will validate each example with schema file
.. command-output:: buildtest schema -n settings.schema.json -e

If you want to retrieve full json schema file for buildtest configuration you can
run ``buildtest schema -n settings.schema.json --json`` or short option ``-j``.
run ``buildtest schema -n settings.schema.json --json`` or short option ``-j``.
5 changes: 5 additions & 0 deletions tests/cli/test_helpcolor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from buildtest.cli.helpcolor import print_available_colors


def test_buildtest_helpcolor():
print_available_colors()

0 comments on commit 6939258

Please sign in to comment.