From 902665bce668a58996de657a65c5ae3002a8810b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 22 Dec 2014 15:17:59 -0500 Subject: add a global --color option If you want to turn off colors for commands, you have to manually adjust the git config settings (in various locations). If you're writing scripts though, you often don't want to modify those locations. Add a commandline option to explicitly control things. The default behavior is unchanged -- we still scan the config files. Change-Id: I54a3fd8e1918bac180aadd7c7d3004f069b02522 --- main.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index 72fb39b0..47f083df 100755 --- a/main.py +++ b/main.py @@ -36,6 +36,7 @@ try: except ImportError: kerberos = None +from color import SetDefaultColoring from trace import SetTrace from git_command import git, GitCommand from git_config import init_ssh, close_ssh @@ -69,6 +70,9 @@ global_options.add_option('-p', '--paginate', global_options.add_option('--no-pager', dest='no_pager', action='store_true', help='disable the pager') +global_options.add_option('--color', + choices=('auto', 'always', 'never'), default=None, + help='control color usage: auto, always, never') global_options.add_option('--trace', dest='trace', action='store_true', help='trace git command execution') @@ -113,6 +117,8 @@ class _Repo(object): print('fatal: invalid usage of --version', file=sys.stderr) return 1 + SetDefaultColoring(gopts.color) + try: cmd = self.commands[name] except KeyError: -- cgit v1.2.3-54-g00ecf