Skip to content

Commit

Permalink
Merge pull request #1284 from buildtesters/issue_1274
Browse files Browse the repository at this point in the history
Added color output for buildtest buildspec maintainers option
  • Loading branch information
shahzebsiddiqui authored Oct 26, 2022
2 parents 79c3f87 + b01048d commit 8afefc9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
32 changes: 24 additions & 8 deletions buildtest/cli/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,14 @@ def list_maintainers(self):
"""Return a list of maintainers"""
return self.cache["maintainers"]

def print_maintainer(self):
"""This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command."""
def print_maintainer(self, color=None):
"""This method prints maintainers from buildspec cache file which implements ``buildtest buildspec maintainers --list`` command.
Args:
color (bool, optional): Print table output of ``buildtest buildspec maintainers --list`` with selected color
"""

consoleColor = checkColor(color)

if self.terse:
if not self.header:
Expand All @@ -821,7 +827,7 @@ def print_maintainer(self):
Column("Maintainers", overflow="fold"),
header_style="blue",
title_style="red",
row_styles=["green"],
row_styles=[consoleColor],
)

for maintainer in self.cache["maintainers"].keys():
Expand All @@ -847,9 +853,15 @@ def print_maintainers_find(self, name):
for file in self.cache["maintainers"][name]:
console.print(file)

def print_maintainers_by_buildspecs(self):
def print_maintainers_by_buildspecs(self, color=None):
"""This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown``
Args:
color (bool, optional): Print table output of ``buildtest buildspec maintainers --breakdown`` with selected color
"""

consoleColor = checkColor(color)

"""This method prints maintainers breakdown by buildspecs. This method implements ``buildtest buildspec maintainers --breakdown``"""
if self.terse:
if not self.header:
print("maintainers|buildspec")
Expand All @@ -865,7 +877,7 @@ def print_maintainers_by_buildspecs(self):
header_style="blue",
style="cyan",
title_style="red",
row_styles=["green"],
row_styles=[consoleColor],
show_lines=True,
)

Expand Down Expand Up @@ -1273,6 +1285,7 @@ def buildspec_maintainers(
breakdown=None,
terse=None,
header=None,
color=None,
name=None,
):
"""Entry point for ``buildtest buildspec maintainers`` command.
Expand All @@ -1282,16 +1295,19 @@ def buildspec_maintainers(
list_maintainers (bool, optional): List all maintainers
terse (bool, optional): Print in terse mode
header (bool, optional): If True disable printing of headers
color (bool, optional): Print output of table with selected color
name (str, optional): List all buildspecs corresponding to maintainer name. This command is specified via ``buildtest buildspec maintainers find <name>``
"""

consoleColor = checkColor(color)

cache = BuildspecCache(configuration=configuration, terse=terse, header=header)

if list_maintainers:
cache.print_maintainer()
cache.print_maintainer(color=consoleColor)

if breakdown:
cache.print_maintainers_by_buildspecs()
cache.print_maintainers_by_buildspecs(color=consoleColor)

if name:
cache.print_maintainers_find(name=name)
Expand Down
1 change: 1 addition & 0 deletions buildtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def main():
breakdown=args.breakdown,
terse=args.terse,
header=args.no_header,
color=args.color,
name=name,
)

Expand Down
13 changes: 11 additions & 2 deletions tests/cli/test_buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from buildtest.config import SiteConfiguration
from buildtest.defaults import BUILDTEST_ROOT
from buildtest.exceptions import BuildTestError
from rich.color import Color

configuration = SiteConfiguration()
configuration.detect_system()
Expand Down Expand Up @@ -149,10 +150,18 @@ def test_buildspec_find_terse():
@pytest.mark.cli
def test_buildspec_maintainers():
buildspec_maintainers(
configuration=configuration, list_maintainers=True, terse=True, header=True
configuration=configuration,
list_maintainers=True,
terse=True,
header=True,
color=Color.default().name,
)
buildspec_maintainers(
configuration=configuration, breakdown=True, terse=True, header=True
configuration=configuration,
breakdown=True,
terse=True,
header=True,
color=Color.default().name,
)
buildspec_maintainers(configuration=configuration, name="@shahzebsiddiqui")

Expand Down

0 comments on commit 8afefc9

Please sign in to comment.