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 pagination for 'buildtest config view' #1218

Merged
merged 2 commits into from
Sep 2, 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
2 changes: 1 addition & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ _buildtest ()
local opts="-h --help"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
view)
local opts="--help --theme -h -t"
local opts="--help --pager --theme -h -p -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )

case "${prev}" in --theme|-t)
Expand Down
4 changes: 3 additions & 1 deletion buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,9 @@ def config_menu(subparsers):
help="Specify a color theme, Pygments style to use when displaying output. See https://pygments.org/docs/styles/#getting-a-list-of-available-styles for available themes",
choices=list(STYLE_MAP.keys()),
)

view_parser.add_argument(
"-p", "--pager", action="store_true", help="Enable PAGING when viewing result"
)
executor_group = executors.add_mutually_exclusive_group()

# buildtest config executors
Expand Down
12 changes: 9 additions & 3 deletions buildtest/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def config_cmd(args, configuration, editor):
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
"""
if args.config == "view":
view_configuration(configuration, theme=args.theme)
view_configuration(configuration, theme=args.theme, pager=args.pager)

elif args.config == "executors":
buildexecutor = BuildExecutor(configuration)
Expand Down Expand Up @@ -130,18 +130,24 @@ def view_path(configuration):
console.print(configuration.file)


def view_configuration(configuration, theme=None):
def view_configuration(configuration, theme=None, pager=None):
"""Display content of buildtest configuration file. This implements command ``buildtest config view``

Args:
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
theme (str, optional): Color theme to choose. This is the Pygments style (https://pygments.org/docs/styles/#getting-a-list-of-available-styles) which is specified by ``--theme`` option
"""

console.rule(configuration.file)
theme = theme or "monokai"
with open(configuration.file, "r") as bc:
syntax = Syntax(bc.read(), "yaml", line_numbers=True, theme=theme)
if pager:
with console.pager():
console.rule(configuration.file)
console.print(syntax)
return

console.rule(configuration.file)
console.print(syntax)


Expand Down
3 changes: 3 additions & 0 deletions tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_view_configuration():
# testing - buildtest config view --theme emacs
view_configuration(configuration, theme="emacs")

# testing - buildtest config view --pager
view_configuration(configuration, pager=True)


def test_valid_config_schemas():

Expand Down