]> rtime.felk.cvut.cz Git - git.git/blobdiff - parse-options.c
Merge branch 'sb/show-branch-parse-options'
[git.git] / parse-options.c
index c52b8ccf59a4848be6f3f810e01029f7c6625c78..1d25b94c72b3fc52eabbdc31a61e43e404ddb303 100644 (file)
@@ -412,6 +412,20 @@ int parse_options(int argc, const char **argv, const struct option *options,
        return parse_options_end(&ctx);
 }
 
+static int usage_argh(const struct option *opts)
+{
+       const char *s;
+       int literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;
+       if (opts->flags & PARSE_OPT_OPTARG)
+               if (opts->long_name)
+                       s = literal ? "[=%s]" : "[=<%s>]";
+               else
+                       s = literal ? "[%s]" : "[<%s>]";
+       else
+               s = literal ? " %s" : " <%s>";
+       return fprintf(stderr, s, opts->argh);
+}
+
 #define USAGE_OPTS_WIDTH 24
 #define USAGE_GAP         2
 
@@ -478,15 +492,9 @@ int usage_with_options_internal(const char * const *usagestr,
                                break;
                        /* FALLTHROUGH */
                case OPTION_STRING:
-                       if (opts->argh) {
-                               if (opts->flags & PARSE_OPT_OPTARG)
-                                       if (opts->long_name)
-                                               pos += fprintf(stderr, "[=<%s>]", opts->argh);
-                                       else
-                                               pos += fprintf(stderr, "[<%s>]", opts->argh);
-                               else
-                                       pos += fprintf(stderr, " <%s>", opts->argh);
-                       } else {
+                       if (opts->argh)
+                               pos += usage_argh(opts);
+                       else {
                                if (opts->flags & PARSE_OPT_OPTARG)
                                        if (opts->long_name)
                                                pos += fprintf(stderr, "[=...]");