summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ffe659f)
raw | patch | inline | side by side (parent: ffe659f)
author | Pierre Habouzit <madcoder@debian.org> | |
Sun, 14 Oct 2007 09:05:12 +0000 (11:05 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 30 Oct 2007 04:03:30 +0000 (21:03 -0700) |
It helps with consistency of the help strings, for example.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
parse-options.c | patch | blob | history | |
parse-options.h | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index c751ebf601825c6354c6e2c7ed650f1693947a45..12a9f9ea68f5ceac24aa4d2f530b68e8c0468983 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
exit(129);
}
+
+/*----- some often used options -----*/
+#include "cache.h"
+int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
+{
+ int v;
+
+ if (!arg) {
+ v = unset ? 0 : DEFAULT_ABBREV;
+ } else {
+ v = strtol(arg, (char **)&arg, 10);
+ if (*arg)
+ return opterror(opt, "expects a numerical value", 0);
+ if (v && v < MINIMUM_ABBREV)
+ v = MINIMUM_ABBREV;
+ else if (v > 40)
+ v = 40;
+ }
+ *(int *)(opt->value) = v;
+ return 0;
+}
diff --git a/parse-options.h b/parse-options.h
index 2b8e7624d67b5796d9e1b38cf65700c5471b98ff..2558e00a7c0eb12a028f4d2e88f2a8f255716604 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
extern NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);
+/*----- some often used options -----*/
+extern int parse_opt_abbrev_cb(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")
+#define OPT__DRY_RUN(var) OPT_BOOLEAN('n', "dry-run", (var), "dry run")
+#define OPT__ABBREV(var) \
+ { OPTION_CALLBACK, 0, "abbrev", (var), "n", \
+ "use <n> digits to display SHA-1s", \
+ PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }
+
#endif