From 451bb210f81c10b60bf90403c9183be26beaaabf Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 2 Feb 2009 06:12:58 +0100 Subject: parse-options: add new function "usage_msg_opt" This function can be used instead of "usage_with_options" when you want to print an error message before the usage string. It may be useful because: if (condition) usage_msg_opt("condition is false", usage, opts); is shorter than: if (condition) { fprintf(stderr, "condition is false\n\n"); usage_with_options(usage, opts); } and may be more consistent. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- parse-options.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index b374ade95c..f0f885c67d 100644 --- a/parse-options.h +++ b/parse-options.h @@ -132,6 +132,10 @@ extern int parse_options(int argc, const char **argv, const char *prefix, extern NORETURN void usage_with_options(const char * const *usagestr, const struct option *options); +extern NORETURN void usage_msg_opt(const char *msg, + const char * const *usagestr, + const struct option *options); + /*----- incremental advanced APIs -----*/ enum { -- cgit v1.2.3 From 86b5efb2864ca50d86437f94ec4c26042cba193e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 27 Jul 2009 20:49:56 +0200 Subject: parse-opt: optionally show "--no-" option string It is usually better to have positive options, to avoid confusing double negations. However, sometimes it is desirable to show the negative option in the help. Introduce the flag PARSE_OPT_NEGHELP to do that. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- parse-options.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index aba30671dc..b32587ad7c 100644 --- a/parse-options.h +++ b/parse-options.h @@ -36,6 +36,7 @@ enum parse_opt_option_flags { PARSE_OPT_LASTARG_DEFAULT = 16, PARSE_OPT_NODASH = 32, PARSE_OPT_LITERAL_ARGHELP = 64, + PARSE_OPT_NEGHELP = 128, }; struct option; @@ -80,6 +81,9 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); * PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets * (i.e. '') in the help message. * Useful for options with multiple parameters. + * PARSE_OPT_NEGHELP: says that the long option should always be shown with + * the --no prefix in the usage message. Sometimes + * useful for users of OPTION_NEGBIT. * * `callback`:: * pointer to the callback to use for OPTION_CALLBACK. -- cgit v1.2.3 From cb6020bb017405cc3e7f1faea6f30d4fd1b62e70 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 4 Dec 2009 00:20:48 -0800 Subject: Teach --[no-]rerere-autoupdate option to merge, revert and friends Introduce a command line option to override rerere.autoupdate configuration variable to make it more useful. Signed-off-by: Junio C Hamano --- parse-options.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index f295a2cf85..91c1500661 100644 --- a/parse-options.h +++ b/parse-options.h @@ -123,6 +123,8 @@ struct option { (h), PARSE_OPT_NOARG, NULL, (p) } #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "n", (h) } #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } +#define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, &parse_opt_tertiary } #define OPT_DATE(s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \ parse_opt_approxidate_cb } @@ -190,6 +192,7 @@ extern int parse_opt_abbrev_cb(const struct option *, const char *, int); extern int parse_opt_approxidate_cb(const struct option *, const char *, int); extern int parse_opt_verbosity_cb(const struct option *, const char *, int); extern int parse_opt_with_commit(const struct option *, const char *, int); +extern int parse_opt_tertiary(const struct option *, const char *, int); #define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose") #define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet") -- cgit v1.2.3 From 41064ebc4920fadb6afafe5f09865d2558921c00 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 11 Jan 2010 22:28:45 -0800 Subject: parse-options.c: mark file-local function static Signed-off-by: Junio C Hamano --- parse-options.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index f295a2cf85..72fa36011b 100644 --- a/parse-options.h +++ b/parse-options.h @@ -171,9 +171,6 @@ struct parse_opt_ctx_t { const char *prefix; }; -extern int parse_options_usage(const char * const *usagestr, - const struct option *opts); - extern void parse_options_start(struct parse_opt_ctx_t *ctx, int argc, const char **argv, const char *prefix, int flags); -- cgit v1.2.3 From 73e9da019655261e456ed862340880de365111f0 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Tue, 16 Feb 2010 23:55:58 -0500 Subject: 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 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 Signed-off-by: Junio C Hamano --- parse-options.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index 0c996916b6..9429f7e361 100644 --- a/parse-options.h +++ b/parse-options.h @@ -135,6 +135,10 @@ struct option { PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) } #define OPT_FILENAME(s, l, v, h) { OPTION_FILENAME, (s), (l), (v), \ "FILE", (h) } +#define OPT_COLOR_FLAG(s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "when", (h), PARSE_OPT_OPTARG, \ + parse_opt_color_flag_cb, (intptr_t)"always" } + /* parse_options() will filter out the processed options and leave the * non-option arguments in argv[]. @@ -187,6 +191,7 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx); /*----- some often used options -----*/ extern int parse_opt_abbrev_cb(const struct option *, const char *, int); extern int parse_opt_approxidate_cb(const struct option *, const char *, int); +extern int parse_opt_color_flag_cb(const struct option *, const char *, int); extern int parse_opt_verbosity_cb(const struct option *, const char *, int); extern int parse_opt_with_commit(const struct option *, const char *, int); extern int parse_opt_tertiary(const struct option *, const char *, int); @@ -203,5 +208,7 @@ extern int parse_opt_tertiary(const struct option *, const char *, int); { OPTION_CALLBACK, 0, "abbrev", (var), "n", \ "use digits to display SHA-1s", \ PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 } +#define OPT__COLOR(var, h) \ + OPT_COLOR_FLAG(0, "color", (var), (h)) #endif -- cgit v1.2.3 From 8b74d75cd26d28d38d2ff88267585fc308b89cef Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 6 Mar 2010 21:34:40 +0100 Subject: parse-options: add parse_options_concat() to concat options Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- parse-options.h | 1 + 1 file changed, 1 insertion(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index 9429f7e361..7581e931da 100644 --- a/parse-options.h +++ b/parse-options.h @@ -187,6 +187,7 @@ extern int parse_options_step(struct parse_opt_ctx_t *ctx, extern int parse_options_end(struct parse_opt_ctx_t *ctx); +extern int parse_options_concat(struct option *dst, size_t, struct option *src); /*----- some often used options -----*/ extern int parse_opt_abbrev_cb(const struct option *, const char *, int); -- cgit v1.2.3 From 4b05548fc0523744b7a1276cfa0f4aae19d6d9c9 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Fri, 14 May 2010 09:31:35 +0000 Subject: enums: omit trailing comma for portability Without this patch at least IBM VisualAge C 5.0 (I have 5.0.2) on AIX 5.1 fails to compile git. enum style is inconsistent already, with some enums declared on one line, some over 3 lines with the enum values all on the middle line, sometimes with 1 enum value per line... and independently of that the trailing comma is sometimes present and other times absent, often mixing with/without trailing comma styles in a single file, and sometimes in consecutive enum declarations. Clearly, omitting the comma is the more portable style, and this patch changes all enum declarations to use the portable omitted dangling comma style consistently. Signed-off-by: Gary V. Vaughan Signed-off-by: Junio C Hamano --- parse-options.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index 7581e931da..678b58db8e 100644 --- a/parse-options.h +++ b/parse-options.h @@ -25,7 +25,7 @@ enum parse_opt_flags { PARSE_OPT_STOP_AT_NON_OPTION = 2, PARSE_OPT_KEEP_ARGV0 = 4, PARSE_OPT_KEEP_UNKNOWN = 8, - PARSE_OPT_NO_INTERNAL_HELP = 16, + PARSE_OPT_NO_INTERNAL_HELP = 16 }; enum parse_opt_option_flags { @@ -36,7 +36,7 @@ enum parse_opt_option_flags { PARSE_OPT_LASTARG_DEFAULT = 16, PARSE_OPT_NODASH = 32, PARSE_OPT_LITERAL_ARGHELP = 64, - PARSE_OPT_NEGHELP = 128, + PARSE_OPT_NEGHELP = 128 }; struct option; @@ -160,7 +160,7 @@ extern NORETURN void usage_msg_opt(const char *msg, enum { PARSE_OPT_HELP = -1, PARSE_OPT_DONE, - PARSE_OPT_UNKNOWN, + PARSE_OPT_UNKNOWN }; /* -- cgit v1.2.3 From 47e9cd28f8a404a0d6293935252ddca5fc243931 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Sat, 12 Jun 2010 14:57:39 +0200 Subject: parseopt: wrap rev-parse --parseopt usage for eval consumption 9c7304e (print the usage string on stdout instead of stderr, 2010-05-17) broke rev-parse --parseopt: when run with -h, the usage notice on stdout ended up in the shell eval. Wrap the usage in a cat <<\EOF ... EOF block when printing to stdout. I do not expect any usage lines to ever start with EOF so this shouldn't be an undue burden. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- parse-options.h | 1 + 1 file changed, 1 insertion(+) (limited to 'parse-options.h') diff --git a/parse-options.h b/parse-options.h index 7581e931da..e16b4d201a 100644 --- a/parse-options.h +++ b/parse-options.h @@ -37,6 +37,7 @@ enum parse_opt_option_flags { PARSE_OPT_NODASH = 32, PARSE_OPT_LITERAL_ARGHELP = 64, PARSE_OPT_NEGHELP = 128, + PARSE_OPT_SHELL_EVAL = 256 }; struct option; -- cgit v1.2.3