summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-06-01 14:09:14 +0900
committerJunio C Hamano <gitster@pobox.com>2017-06-01 14:56:18 +0900
commit60f32610243165e43afca785a85c38967130a70f (patch)
treeb32cebc3328c5e63aef5f573bd82569fb3c48caa /usage.c
parent29ec62700ad3db6be572c6f3c03a7d0443c86353 (diff)
downloadgit-jc/wip-check-help-option.tar.gz
check_help_option(): a helper for early check of "-h" optionjc/wip-check-help-option
As "show help when we get '-h' as the only option." often appears, let's give an easy helper to call for these call sites. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/usage.c b/usage.c
index 2f87ca69a8..007d732094 100644
--- a/usage.c
+++ b/usage.c
@@ -5,6 +5,7 @@
*/
#include "git-compat-util.h"
#include "cache.h"
+#include "parse-options.h"
void vreportf(const char *prefix, const char *err, va_list params)
{
@@ -225,3 +226,13 @@ NORETURN void BUG(const char *fmt, ...)
va_end(ap);
}
#endif
+
+void check_help_option(int argc, const char **argv, const void *help, struct option *opt)
+{
+ if (argc == 2 && !strcmp(argv[1], "-h")) {
+ if (opt)
+ usage_with_options((const char * const *)help, opt);
+ else
+ usage((const char *)help);
+ }
+}