Skip to content

Commit 2b5c220

Browse files
committed
Add --color global option
Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 8400509 commit 2b5c220

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

simpleflow/command.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import swf.querysets
1919

2020
from simpleflow.history import History
21+
from simpleflow.settings import logging_formatter
22+
from simpleflow.settings.logging_formatter import ColorModes
2123
from simpleflow.swf.stats import pretty
2224
from simpleflow.swf import helpers
2325
from simpleflow.swf.process import decider
@@ -76,11 +78,14 @@ def comma_separated_list(value):
7678
@click.group()
7779
@click.option('--format')
7880
@click.option('--header/--no-header', default=False)
81+
@click.option('--color', type=click.Choice([ColorModes.AUTO, ColorModes.ALWAYS, ColorModes.NEVER]),
82+
default=ColorModes.AUTO)
7983
@click.version_option(version=__version__)
8084
@click.pass_context
81-
def cli(ctx, header, format):
85+
def cli(ctx, header, format, color):
8286
ctx.params['format'] = format
8387
ctx.params['header'] = header
88+
logging_formatter.color_mode = color
8489

8590

8691
def get_workflow_type(domain_name, workflow_class):

simpleflow/settings/logging_formatter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010
END = '\033[0m'
1111

1212

13+
class ColorModes(object):
14+
AUTO = 'auto'
15+
ALWAYS = 'always'
16+
NEVER = 'never'
17+
18+
color_mode = 'auto'
19+
20+
1321
def colorize(level, message):
1422
# if not in a tty, we're likely redirected or piped
15-
if not sys.stdout.isatty():
23+
if color_mode == ColorModes.NEVER or (color_mode == ColorModes.AUTO and not sys.stdout.isatty()):
1624
return message
1725

1826
# color mappings

0 commit comments

Comments
 (0)