Skip to content

Commit eeb03a2

Browse files
authored
Merge pull request #168 from Kuniwak/support-no-color
Support --no-color option
2 parents 9080bc5 + cc0499a commit eeb03a2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

vint/linting/cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _build_argparser(self):
7272
parser.add_argument('-s', '--style-problem', action='store_const', const=True, help='report errors, warnings and style problems')
7373
parser.add_argument('-m', '--max-violations', type=int, help='limit max violations count')
7474
parser.add_argument('-c', '--color', action='store_const', const=True, help='colorize output when possible')
75+
parser.add_argument('--no-color', action='store_const', const=True, help='do not colorize output')
7576
parser.add_argument('-j', '--json', action='store_const', const=True, help='output json style')
7677
parser.add_argument('-t', '--stat', action='store_const', const=True, help='output statistic info')
7778
parser.add_argument('--enable-neovim', action='store_const', const=True, help='Enable Neovim syntax')

vint/linting/config/config_cmdargs_source.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
from vint.linting.level import Level
33

44

5+
class ConflictedOptionsError(Exception):
6+
def __init__(self, conflicted_option_names):
7+
self.conflicted_option_names = conflicted_option_names
8+
9+
def __str__(self):
10+
option_names = ', '.join(self.conflicted_option_names)
11+
return 'These options are conflicted: {0}'.format(option_names)
12+
13+
514
class ConfigCmdargsSource(ConfigSource):
615
def __init__(self, env):
716
self._config_dict = self._build_config_dict(env)
@@ -45,7 +54,21 @@ def _normalize_json(self, env, config_dict):
4554

4655

4756
def _normalize_color(self, env, config_dict):
48-
return self._pass_config_by_key('color', env, config_dict)
57+
env_cmdargs = env['cmdargs']
58+
59+
should_colorize = 'color' in env_cmdargs and env_cmdargs['color'] is not None
60+
should_not_colorize = 'no_color' in env_cmdargs and env_cmdargs['no_color'] is not None
61+
62+
if should_colorize and should_not_colorize:
63+
raise ConflictedOptionsError(['color', 'no_color'])
64+
65+
if should_colorize:
66+
config_dict['cmdargs']['color'] = True
67+
68+
if should_not_colorize:
69+
config_dict['cmdargs']['color'] = False
70+
71+
return config_dict
4972

5073

5174
def _normalize_verbose(self, env, config_dict):

0 commit comments

Comments
 (0)