comparison piecrust/main.py @ 579:42a5e78e782a

cli: Add `--no-color` option.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 30 Dec 2015 14:46:51 -0800
parents 353a0b30f412
children 1eda551ee681
comparison
equal deleted inserted replaced
578:683be25cbdb2 579:42a5e78e782a
84 self.log_file = log_file 84 self.log_file = log_file
85 self.log_debug = log_debug 85 self.log_debug = log_debug
86 self.config_variant = config_variant 86 self.config_variant = config_variant
87 self.config_values = [] 87 self.config_values = []
88 self.debug_only = [] 88 self.debug_only = []
89 self.no_color = False
89 90
90 91
91 def _parse_config_value(arg): 92 def _parse_config_value(arg):
92 try: 93 try:
93 name, value = arg.split('=') 94 name, value = arg.split('=')
133 res.cache = False 134 res.cache = False
134 elif arg == '--debug': 135 elif arg == '--debug':
135 res.debug = True 136 res.debug = True
136 elif arg == '--quiet': 137 elif arg == '--quiet':
137 res.quiet = True 138 res.quiet = True
139 elif arg == '--no-color':
140 res.no_color = True
138 else: 141 else:
139 break 142 break
140 143
141 i = i + 1 144 i = i + 1
142 145
143 # Setup the logger. 146 # Setup the logger.
144 if res.debug and res.quiet: 147 if res.debug and res.quiet:
145 raise Exception("You can't specify both --debug and --quiet.") 148 raise Exception("You can't specify both --debug and --quiet.")
146 149
147 colorama.init() 150 strip_colors = None
151 if res.no_color:
152 strip_colors = True
153
154 colorama.init(strip=strip_colors)
148 root_logger = logging.getLogger() 155 root_logger = logging.getLogger()
149 root_logger.setLevel(logging.INFO) 156 root_logger.setLevel(logging.INFO)
150 if res.debug or res.log_debug: 157 if res.debug or res.log_debug:
151 root_logger.setLevel(logging.DEBUG) 158 root_logger.setLevel(logging.DEBUG)
152 159
241 help="Send log messages to the specified file.") 248 help="Send log messages to the specified file.")
242 parser.add_argument( 249 parser.add_argument(
243 '--log-debug', 250 '--log-debug',
244 help="Log debug messages to the log file.", 251 help="Log debug messages to the log file.",
245 action='store_true') 252 action='store_true')
253 parser.add_argument(
254 '--no-color',
255 help="Don't use colorized output.",
256 action='store_true')
246 257
247 commands = sorted(app.plugin_loader.getCommands(), 258 commands = sorted(app.plugin_loader.getCommands(),
248 key=lambda c: c.name) 259 key=lambda c: c.name)
249 subparsers = parser.add_subparsers(title='list of commands') 260 subparsers = parser.add_subparsers(title='list of commands')
250 for c in commands: 261 for c in commands: