88from typing import Union
99
1010import pre_commit .constants as C
11- from pre_commit import color
1211from pre_commit import git
12+ from pre_commit .color import add_color_option
1313from pre_commit .commands .autoupdate import autoupdate
1414from pre_commit .commands .clean import clean
1515from pre_commit .commands .gc import gc
4141COMMANDS_NO_GIT = {'clean' , 'gc' , 'init-templatedir' , 'sample-config' }
4242
4343
44- def _add_color_option (parser : argparse .ArgumentParser ) -> None :
45- parser .add_argument (
46- '--color' , default = os .environ .get ('PRE_COMMIT_COLOR' , 'auto' ),
47- type = color .use_color ,
48- metavar = '{' + ',' .join (color .COLOR_CHOICES ) + '}' ,
49- help = 'Whether to use color in output. Defaults to `%(default)s`.' ,
50- )
51-
52-
5344def _add_config_option (parser : argparse .ArgumentParser ) -> None :
5445 parser .add_argument (
5546 '-c' , '--config' , default = C .CONFIG_FILE ,
@@ -195,7 +186,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
195186 'autoupdate' ,
196187 help = "Auto-update pre-commit config to the latest repos' versions." ,
197188 )
198- _add_color_option (autoupdate_parser )
189+ add_color_option (autoupdate_parser )
199190 _add_config_option (autoupdate_parser )
200191 autoupdate_parser .add_argument (
201192 '--bleeding-edge' , action = 'store_true' ,
@@ -216,11 +207,11 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
216207 clean_parser = subparsers .add_parser (
217208 'clean' , help = 'Clean out pre-commit files.' ,
218209 )
219- _add_color_option (clean_parser )
210+ add_color_option (clean_parser )
220211 _add_config_option (clean_parser )
221212
222213 hook_impl_parser = subparsers .add_parser ('hook-impl' )
223- _add_color_option (hook_impl_parser )
214+ add_color_option (hook_impl_parser )
224215 _add_config_option (hook_impl_parser )
225216 hook_impl_parser .add_argument ('--hook-type' )
226217 hook_impl_parser .add_argument ('--hook-dir' )
@@ -230,7 +221,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
230221 hook_impl_parser .add_argument (dest = 'rest' , nargs = argparse .REMAINDER )
231222
232223 gc_parser = subparsers .add_parser ('gc' , help = 'Clean unused cached repos.' )
233- _add_color_option (gc_parser )
224+ add_color_option (gc_parser )
234225 _add_config_option (gc_parser )
235226
236227 init_templatedir_parser = subparsers .add_parser (
@@ -240,7 +231,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
240231 '`git config init.templateDir`.'
241232 ),
242233 )
243- _add_color_option (init_templatedir_parser )
234+ add_color_option (init_templatedir_parser )
244235 _add_config_option (init_templatedir_parser )
245236 init_templatedir_parser .add_argument (
246237 'directory' , help = 'The directory in which to write the hook script.' ,
@@ -256,7 +247,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
256247 install_parser = subparsers .add_parser (
257248 'install' , help = 'Install the pre-commit script.' ,
258249 )
259- _add_color_option (install_parser )
250+ add_color_option (install_parser )
260251 _add_config_option (install_parser )
261252 install_parser .add_argument (
262253 '-f' , '--overwrite' , action = 'store_true' ,
@@ -286,32 +277,32 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
286277 'useful.'
287278 ),
288279 )
289- _add_color_option (install_hooks_parser )
280+ add_color_option (install_hooks_parser )
290281 _add_config_option (install_hooks_parser )
291282
292283 migrate_config_parser = subparsers .add_parser (
293284 'migrate-config' ,
294285 help = 'Migrate list configuration to new map configuration.' ,
295286 )
296- _add_color_option (migrate_config_parser )
287+ add_color_option (migrate_config_parser )
297288 _add_config_option (migrate_config_parser )
298289
299290 run_parser = subparsers .add_parser ('run' , help = 'Run hooks.' )
300- _add_color_option (run_parser )
291+ add_color_option (run_parser )
301292 _add_config_option (run_parser )
302293 _add_run_options (run_parser )
303294
304295 sample_config_parser = subparsers .add_parser (
305296 'sample-config' , help = f'Produce a sample { C .CONFIG_FILE } file' ,
306297 )
307- _add_color_option (sample_config_parser )
298+ add_color_option (sample_config_parser )
308299 _add_config_option (sample_config_parser )
309300
310301 try_repo_parser = subparsers .add_parser (
311302 'try-repo' ,
312303 help = 'Try the hooks in a repository, useful for developing new hooks.' ,
313304 )
314- _add_color_option (try_repo_parser )
305+ add_color_option (try_repo_parser )
315306 _add_config_option (try_repo_parser )
316307 try_repo_parser .add_argument (
317308 'repo' , help = 'Repository to source hooks from.' ,
@@ -328,7 +319,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
328319 uninstall_parser = subparsers .add_parser (
329320 'uninstall' , help = 'Uninstall the pre-commit script.' ,
330321 )
331- _add_color_option (uninstall_parser )
322+ add_color_option (uninstall_parser )
332323 _add_config_option (uninstall_parser )
333324 _add_hook_type_option (uninstall_parser )
334325
0 commit comments