Skip to content

Commit

Permalink
cli: add a -n/--no-colors option
Browse files Browse the repository at this point in the history
Bug: T212783
Change-Id: Ie243177f29018f95f59f0261b6e2b9258b56c607
  • Loading branch information
volans- committed Sep 10, 2020
1 parent c9a20e9 commit b715b6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Small improvements
* global: allow to log the whole output to a specific file, to allow multiple people follow the progress.
* global: allow to randomize the list hosts before execution `T164587`_.
* CLI: improve the dry-run mode to show what would have been done.
* CLI: add a ``--color`` or a ``--no-color`` option to manage the output color.
* CLI: read commands from a file, one per line.
* CLI: add ``--limit`` to randomly select N hosts within a broader selection.
* puppetdb backend: improve globbing support, check if fnmatch could be used without conflicting with ClusterShell
Expand Down
3 changes: 3 additions & 0 deletions cumin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_parser():
help='Specify a different output format. [default: None]')
parser.add_argument('-i', '--interactive', action='store_true',
help='Drop into a Python shell with the results. [default: False]')
parser.add_argument('-n', '--no-colors', action='store_true', help='Disable colored output. [default: False]')
parser.add_argument('--force', action='store_true',
help=('USE WITH CAUTION! Force the execution without confirmation of the affected hosts. '
'[default: False]'))
Expand Down Expand Up @@ -183,6 +184,8 @@ def parse_args(argv):
"""
parser = get_parser()
parsed_args = parser.parse_args(argv)
if parsed_args.no_colors:
Colored.disabled = True

# Validation and default values
num_commands = len(parsed_args.commands)
Expand Down
9 changes: 9 additions & 0 deletions cumin/tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from cumin import cli, CuminError, LOGGING_TRACE_LEVEL_NUMBER, nodeset, transports
from cumin.color import Colored


# Environment variables
Expand Down Expand Up @@ -62,6 +63,14 @@ def test_parse_args_no_mode():
cli.parse_args(_ARGV[:index] + _ARGV[index + 1:])


def test_parse_args_no_colors():
"""If -n/--no-colors is specified, the colors should be globally disabled."""
assert not Colored.disabled
cli.parse_args(_ARGV[:2] + ['-n'] + _ARGV[3:])
assert Colored.disabled
Colored.disabled = False # Reset it


def test_target_batch_size():
"""Calling target_batch_size() should properly parse integer values."""
assert cli.target_batch_size('1') == {'value': 1, 'ratio': None}
Expand Down

0 comments on commit b715b6c

Please sign in to comment.