aboutsummaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorMark Lodato <lodatom@gmail.com>2010-02-16 23:55:58 -0500
committerJunio C Hamano <gitster@pobox.com>2010-02-18 17:21:40 -0800
commit73e9da019655261e456ed862340880de365111f0 (patch)
tree3668881735169164f975f4db0983241cf3d631ba /parse-options.c
parente923eaeb901ff056421b9007adcbbce271caa7b6 (diff)
downloadgit-73e9da019655261e456ed862340880de365111f0.tar.gz
git-73e9da019655261e456ed862340880de365111f0.tar.xz
Add an optional argument for --color options
Make git-branch, git-show-branch, git-grep, and all the diff-based programs accept an optional argument <when> for --color. The argument is a colorbool: "always", "never", or "auto". If no argument is given, "always" is used; --no-color is an alias for --color=never. This makes the command-line interface consistent with other GNU tools, such as `ls' and `grep', and with the git-config color options. Note that, without an argument, --color and --no-color work exactly as before. To implement this, two internal changes were made: 1. Allow the first argument of git_config_colorbool() to be NULL, in which case it returns -1 if the argument isn't "always", "never", or "auto". 2. Add OPT_COLOR_FLAG(), OPT__COLOR(), and parse_opt_color_flag_cb() to the option parsing library. The callback uses git_config_colorbool(), so color.h is now a dependency of parse-options.c. Signed-off-by: Mark Lodato <lodatom@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c
index d218122af..c83035d01 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -2,6 +2,7 @@
#include "parse-options.h"
#include "cache.h"
#include "commit.h"
+#include "color.h"
static int parse_options_usage(const char * const *usagestr,
const struct option *opts);
@@ -599,6 +600,21 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
return 0;
}
+int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
+ int unset)
+{
+ int value;
+
+ if (!arg)
+ arg = unset ? "never" : (const char *)opt->defval;
+ value = git_config_colorbool(NULL, arg, -1);
+ if (value < 0)
+ return opterror(opt,
+ "expects \"always\", \"auto\", or \"never\"", 0);
+ *(int *)opt->value = value;
+ return 0;
+}
+
int parse_opt_verbosity_cb(const struct option *opt, const char *arg,
int unset)
{