{"thread":{"id":"19648","subject":"[PATCH] parse-options: make OPT_NUMBER's argh explicit","startedAt":"2009-06-03T07:49:27Z","lastAt":"2009-06-06T10:30:19Z","messageCount":7,"participants":["Stephen Boyd","René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"115324","messageId":"1244015367-16998-1-git-send-email-bebarino@gmail.com","threadId":"19648","inReplyTo":null,"subject":"[PATCH] parse-options: make OPT_NUMBER's argh explicit","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-03T07:49:27Z","receivedAt":"2009-06-03T07:49:27Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"OPTION_NUMBER hard codes its argh member to be \"n\", but the decision is\nhidden deep in usage_with_options_internal(). Make \"n\" the default argh\nfor the OPT_NUMBER macro while leaving it undecided for the OPTION_NUMBER\nenum.\n\nThis make it less surprising to users that argh is \"n\" when using the\nOPT_NUMBER macro.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n builtin-tag.c   |    4 ++--\n parse-options.c |   11 ++---------\n parse-options.h |    2 +-\n 3 files changed, 5 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex dc3db62..080e04a 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -376,8 +376,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstruct commit_list *with_commit = NULL;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN('l', NULL, &list, \"list tag names\"),\n-\t\t{ OPTION_INTEGER, 'n', NULL, &lines, NULL,\n-\t\t\t\t\"print n lines of each tag message\",\n+\t\t{ OPTION_INTEGER, 'n', NULL, &lines, \"n\",\n+\t\t\t\t\"print <n> lines of each tag message\",\n \t\t\t\tPARSE_OPT_OPTARG, NULL, 1 },\n \t\tOPT_BOOLEAN('d', NULL, &delete, \"delete tags\"),\n \t\tOPT_BOOLEAN('v', NULL, &verify, \"verify tags\"),\ndiff --git a/parse-options.c b/parse-options.c\nindex b85cab2..48ba62b 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -503,19 +503,12 @@ int usage_with_options_internal(const char * const *usagestr,\n \t\tswitch (opts->type) {\n \t\tcase OPTION_ARGUMENT:\n \t\t\tbreak;\n-\t\tcase OPTION_INTEGER:\n-\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n-\t\t\t\tif (opts->long_name)\n-\t\t\t\t\tpos += fprintf(stderr, \"[=<n>]\");\n-\t\t\t\telse\n-\t\t\t\t\tpos += fprintf(stderr, \"[<n>]\");\n-\t\t\telse\n-\t\t\t\tpos += fprintf(stderr, \" <n>\");\n-\t\t\tbreak;\n \t\tcase OPTION_CALLBACK:\n \t\t\tif (opts->flags & PARSE_OPT_NOARG)\n \t\t\t\tbreak;\n \t\t\t/* FALLTHROUGH */\n+\t\tcase OPTION_INTEGER:\n+\t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_FILENAME:\n \t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_STRING:\ndiff --git a/parse-options.h b/parse-options.h\nindex b374ade..b141ae6 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -108,7 +108,7 @@ struct option {\n #define OPT_BOOLEAN(s, l, v, h)     { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }\n #define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }\n #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }\n-#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), NULL, (h) }\n+#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), \"n\", (h) }\n #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }\n #define OPT_DATE(s, l, v, h) \\\n \t{ OPTION_CALLBACK, (s), (l), (v), \"time\",(h), 0, \\\n-- \n1.6.3.1.244.gf9275\n"},{"id":"115328","messageId":"4A264DFA.3090309@lsrfire.ath.cx","threadId":"19648","inReplyTo":"1244015367-16998-1-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH] parse-options: make OPT_NUMBER's argh explicit","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-06-03T10:18:34Z","receivedAt":"2009-06-03T10:18:34Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Stephen Boyd schrieb:\n> OPTION_NUMBER hard codes its argh member to be \"n\", but the decision is\n> hidden deep in usage_with_options_internal(). Make \"n\" the default argh\n> for the OPT_NUMBER macro while leaving it undecided for the OPTION_NUMBER\n> enum.\n> \n> This make it less surprising to users that argh is \"n\" when using the\n> OPT_NUMBER macro.\n> \n> Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n> ---\n>  builtin-tag.c   |    4 ++--\n>  parse-options.c |   11 ++---------\n>  parse-options.h |    2 +-\n>  3 files changed, 5 insertions(+), 12 deletions(-)\n> \n> diff --git a/builtin-tag.c b/builtin-tag.c\n> index dc3db62..080e04a 100644\n> --- a/builtin-tag.c\n> +++ b/builtin-tag.c\n> @@ -376,8 +376,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n>  \tstruct commit_list *with_commit = NULL;\n>  \tstruct option options[] = {\n>  \t\tOPT_BOOLEAN('l', NULL, &list, \"list tag names\"),\n> -\t\t{ OPTION_INTEGER, 'n', NULL, &lines, NULL,\n> -\t\t\t\t\"print n lines of each tag message\",\n> +\t\t{ OPTION_INTEGER, 'n', NULL, &lines, \"n\",\n> +\t\t\t\t\"print <n> lines of each tag message\",\n>  \t\t\t\tPARSE_OPT_OPTARG, NULL, 1 },\n>  \t\tOPT_BOOLEAN('d', NULL, &delete, \"delete tags\"),\n>  \t\tOPT_BOOLEAN('v', NULL, &verify, \"verify tags\"),\n> diff --git a/parse-options.c b/parse-options.c\n> index b85cab2..48ba62b 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -503,19 +503,12 @@ int usage_with_options_internal(const char * const *usagestr,\n>  \t\tswitch (opts->type) {\n>  \t\tcase OPTION_ARGUMENT:\n>  \t\t\tbreak;\n> -\t\tcase OPTION_INTEGER:\n> -\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n> -\t\t\t\tif (opts->long_name)\n> -\t\t\t\t\tpos += fprintf(stderr, \"[=<n>]\");\n> -\t\t\t\telse\n> -\t\t\t\t\tpos += fprintf(stderr, \"[<n>]\");\n> -\t\t\telse\n> -\t\t\t\tpos += fprintf(stderr, \" <n>\");\n> -\t\t\tbreak;\n>  \t\tcase OPTION_CALLBACK:\n>  \t\t\tif (opts->flags & PARSE_OPT_NOARG)\n>  \t\t\t\tbreak;\n>  \t\t\t/* FALLTHROUGH */\n> +\t\tcase OPTION_INTEGER:\n> +\t\t\t/* FALLTHROUGH */\n>  \t\tcase OPTION_FILENAME:\n>  \t\t\t/* FALLTHROUGH */\n>  \t\tcase OPTION_STRING:\n> diff --git a/parse-options.h b/parse-options.h\n> index b374ade..b141ae6 100644\n> --- a/parse-options.h\n> +++ b/parse-options.h\n> @@ -108,7 +108,7 @@ struct option {\n>  #define OPT_BOOLEAN(s, l, v, h)     { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }\n>  #define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }\n>  #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }\n> -#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), NULL, (h) }\n> +#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), \"n\", (h) }\n>  #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }\n>  #define OPT_DATE(s, l, v, h) \\\n>  \t{ OPTION_CALLBACK, (s), (l), (v), \"time\",(h), 0, \\\n\nNice code reduction.  s/NUMBER/INTEGER/ in the commit message?\n\nBy the way, can the switch be replaced by a simple check for\nPARSE_OPT_NOARG now?\n\nRené\n"},{"id":"115365","messageId":"780e0a6b0906031235q1438b76cyba1172556c94d1d0@mail.gmail.com","threadId":"19648","inReplyTo":"4A264DFA.3090309@lsrfire.ath.cx","subject":"Re: [PATCH] parse-options: make OPT_NUMBER's argh explicit","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-03T19:35:27Z","receivedAt":"2009-06-03T19:35:27Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On Wed, Jun 3, 2009 at 3:18 AM, René Scharfe<rene.scharfe@lsrfire.ath.cx> wrote:\n>\n> Nice code reduction.  s/NUMBER/INTEGER/ in the commit message?\n\nOops. Thanks, I'll fix that.\n\n>\n> By the way, can the switch be replaced by a simple check for\n> PARSE_OPT_NOARG now?\n>\n\nThis looks possible. I think just set PARSE_OPT_NOARG as the flag of\nthe appropriate OPT_* macros. I'll have to grep the tree for custom\nuses of OPTION_* though.\n\nShould that be all squashed together? Or maybe that could be a follow up patch?\n"},{"id":"115370","messageId":"4A26DBA3.90604@lsrfire.ath.cx","threadId":"19648","inReplyTo":"780e0a6b0906031235q1438b76cyba1172556c94d1d0@mail.gmail.com","subject":"Re: [PATCH] parse-options: make OPT_NUMBER's argh explicit","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-06-03T20:22:59Z","receivedAt":"2009-06-03T20:22:59Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Stephen Boyd schrieb:\n> On Wed, Jun 3, 2009 at 3:18 AM, René Scharfe<rene.scharfe@lsrfire.ath.cx> wrote:\n>> By the way, can the switch be replaced by a simple check for\n>> PARSE_OPT_NOARG now?\n>>\n> \n> This looks possible. I think just set PARSE_OPT_NOARG as the flag of\n> the appropriate OPT_* macros. I'll have to grep the tree for custom\n> uses of OPTION_* though.\n\nYes, it's only worthwhile if there aren't too many special cases that\nrequire explicit setting of PARSE_OPT_NOARG.\n\n> \n> Should that be all squashed together? Or maybe that could be a follow up patch?\n\nYour existing patch looks fine as is, I'd keep additional changes\nseparate.\n\nHmm, and how about the following in between them?\n\n parse-options.c |   16 +++-------------\n 1 files changed, 3 insertions(+), 13 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex b85cab2..dda36b1 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -440,7 +440,7 @@ int parse_options(int argc, const char **argv, const char *prefix,\n static int usage_argh(const struct option *opts)\n {\n \tconst char *s;\n-\tint literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;\n+\tint literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opt->argh;\n \tif (opts->flags & PARSE_OPT_OPTARG)\n \t\tif (opts->long_name)\n \t\t\ts = literal ? \"[=%s]\" : \"[=<%s>]\";\n@@ -448,7 +448,7 @@ static int usage_argh(const struct option *opts)\n \t\t\ts = literal ? \"[%s]\" : \"[<%s>]\";\n \telse\n \t\ts = literal ? \" %s\" : \" <%s>\";\n-\treturn fprintf(stderr, s, opts->argh);\n+\treturn fprintf(stderr, s, opt->argh ? opt->argh : \"...\");\n }\n \n #define USAGE_OPTS_WIDTH 24\n@@ -519,17 +519,7 @@ int usage_with_options_internal(const char * const *usagestr,\n \t\tcase OPTION_FILENAME:\n \t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_STRING:\n-\t\t\tif (opts->argh)\n-\t\t\t\tpos += usage_argh(opts);\n-\t\t\telse {\n-\t\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n-\t\t\t\t\tif (opts->long_name)\n-\t\t\t\t\t\tpos += fprintf(stderr, \"[=...]\");\n-\t\t\t\t\telse\n-\t\t\t\t\t\tpos += fprintf(stderr, \"[...]\");\n-\t\t\t\telse\n-\t\t\t\t\tpos += fprintf(stderr, \" ...\");\n-\t\t\t}\n+\t\t\tpos += usage_argh(opts);\n \t\t\tbreak;\n \t\tdefault: /* OPTION_{BIT,BOOLEAN,NUMBER,SET_INT,SET_PTR} */\n \t\t\tbreak;\n"},{"id":"115459","messageId":"1244159037-9292-1-git-send-email-bebarino@gmail.com","threadId":"19648","inReplyTo":"4A26DBA3.90604@lsrfire.ath.cx","subject":"[PATCHv2 1/2] parse-options: make OPT_INTEGER's argh explicit","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-04T23:43:56Z","receivedAt":"2009-06-04T23:43:56Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"OPTION_INTEGER hardcodes its argh member to be \"n\", but the decision is\nhidden deep in usage_with_options_internal(). Make \"n\" the default argh\nfor the OPT_INTEGER macro while leaving it undecided for the OPTION_INTEGER\nenum.\n\nThis make it less suprising to users that argh is \"n\" when using the\nOPT_INTEGER macro.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n builtin-tag.c   |    4 ++--\n parse-options.c |   11 ++---------\n parse-options.h |    2 +-\n 3 files changed, 5 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-tag.c b/builtin-tag.c\nindex dc3db62..080e04a 100644\n--- a/builtin-tag.c\n+++ b/builtin-tag.c\n@@ -376,8 +376,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstruct commit_list *with_commit = NULL;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN('l', NULL, &list, \"list tag names\"),\n-\t\t{ OPTION_INTEGER, 'n', NULL, &lines, NULL,\n-\t\t\t\t\"print n lines of each tag message\",\n+\t\t{ OPTION_INTEGER, 'n', NULL, &lines, \"n\",\n+\t\t\t\t\"print <n> lines of each tag message\",\n \t\t\t\tPARSE_OPT_OPTARG, NULL, 1 },\n \t\tOPT_BOOLEAN('d', NULL, &delete, \"delete tags\"),\n \t\tOPT_BOOLEAN('v', NULL, &verify, \"verify tags\"),\ndiff --git a/parse-options.c b/parse-options.c\nindex b85cab2..48ba62b 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -503,19 +503,12 @@ int usage_with_options_internal(const char * const *usagestr,\n \t\tswitch (opts->type) {\n \t\tcase OPTION_ARGUMENT:\n \t\t\tbreak;\n-\t\tcase OPTION_INTEGER:\n-\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n-\t\t\t\tif (opts->long_name)\n-\t\t\t\t\tpos += fprintf(stderr, \"[=<n>]\");\n-\t\t\t\telse\n-\t\t\t\t\tpos += fprintf(stderr, \"[<n>]\");\n-\t\t\telse\n-\t\t\t\tpos += fprintf(stderr, \" <n>\");\n-\t\t\tbreak;\n \t\tcase OPTION_CALLBACK:\n \t\t\tif (opts->flags & PARSE_OPT_NOARG)\n \t\t\t\tbreak;\n \t\t\t/* FALLTHROUGH */\n+\t\tcase OPTION_INTEGER:\n+\t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_FILENAME:\n \t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_STRING:\ndiff --git a/parse-options.h b/parse-options.h\nindex b374ade..b141ae6 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -108,7 +108,7 @@ struct option {\n #define OPT_BOOLEAN(s, l, v, h)     { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }\n #define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }\n #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }\n-#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), NULL, (h) }\n+#define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), \"n\", (h) }\n #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }\n #define OPT_DATE(s, l, v, h) \\\n \t{ OPTION_CALLBACK, (s), (l), (v), \"time\",(h), 0, \\\n-- \n1.6.3.1.266.gb11cf\n"},{"id":"115460","messageId":"1244159037-9292-2-git-send-email-bebarino@gmail.com","threadId":"19648","inReplyTo":"1244159037-9292-1-git-send-email-bebarino@gmail.com","subject":"[PATCHv2 2/2] parse-options: simplify usage argh handling","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-06-04T23:43:57Z","receivedAt":"2009-06-04T23:43:57Z","isPatch":false,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Simplify the argh printing by simply calling usage_argh() if the option\ncan take an argument. Update macros defined in parse-options.h to set\nthe PARSE_OPT_NOARG flag.\n\nThe only other user of custom non-argument taking options is git-apply\n(in this case OPTION_BOOLEAN for deprecated options). Update it to set\nthe PARSE_OPT_NOARG flag.\n\nThanks to René Scharfe for the suggestion and starter patch.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nRené, feel free to signoff if you like.\n\n builtin-apply.c |    6 ++++--\n parse-options.c |   33 ++++-----------------------------\n parse-options.h |   20 +++++++++++++-------\n 3 files changed, 21 insertions(+), 38 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 94ba2bd..89a5185 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -3277,9 +3277,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)\n \t\tOPT_BOOLEAN(0, \"stat\", &diffstat,\n \t\t\t\"instead of applying the patch, output diffstat for the input\"),\n \t\t{ OPTION_BOOLEAN, 0, \"allow-binary-replacement\", &binary,\n-\t\t  NULL, \"old option, now no-op\", PARSE_OPT_HIDDEN },\n+\t\t  NULL, \"old option, now no-op\",\n+\t\t  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG },\n \t\t{ OPTION_BOOLEAN, 0, \"binary\", &binary,\n-\t\t  NULL, \"old option, now no-op\", PARSE_OPT_HIDDEN },\n+\t\t  NULL, \"old option, now no-op\",\n+\t\t  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG },\n \t\tOPT_BOOLEAN(0, \"numstat\", &numstat,\n \t\t\t\"shows number of added and deleted lines in decimal notation\"),\n \t\tOPT_BOOLEAN(0, \"summary\", &summary,\ndiff --git a/parse-options.c b/parse-options.c\nindex 48ba62b..e469fc0 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -440,7 +440,7 @@ int parse_options(int argc, const char **argv, const char *prefix,\n static int usage_argh(const struct option *opts)\n {\n \tconst char *s;\n-\tint literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;\n+\tint literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh;\n \tif (opts->flags & PARSE_OPT_OPTARG)\n \t\tif (opts->long_name)\n \t\t\ts = literal ? \"[=%s]\" : \"[=<%s>]\";\n@@ -448,7 +448,7 @@ static int usage_argh(const struct option *opts)\n \t\t\ts = literal ? \"[%s]\" : \"[<%s>]\";\n \telse\n \t\ts = literal ? \" %s\" : \" <%s>\";\n-\treturn fprintf(stderr, s, opts->argh);\n+\treturn fprintf(stderr, s, opts->argh ? opts->argh : \"...\");\n }\n \n #define USAGE_OPTS_WIDTH 24\n@@ -500,33 +500,8 @@ int usage_with_options_internal(const char * const *usagestr,\n \t\tif (opts->type == OPTION_NUMBER)\n \t\t\tpos += fprintf(stderr, \"-NUM\");\n \n-\t\tswitch (opts->type) {\n-\t\tcase OPTION_ARGUMENT:\n-\t\t\tbreak;\n-\t\tcase OPTION_CALLBACK:\n-\t\t\tif (opts->flags & PARSE_OPT_NOARG)\n-\t\t\t\tbreak;\n-\t\t\t/* FALLTHROUGH */\n-\t\tcase OPTION_INTEGER:\n-\t\t\t/* FALLTHROUGH */\n-\t\tcase OPTION_FILENAME:\n-\t\t\t/* FALLTHROUGH */\n-\t\tcase OPTION_STRING:\n-\t\t\tif (opts->argh)\n-\t\t\t\tpos += usage_argh(opts);\n-\t\t\telse {\n-\t\t\t\tif (opts->flags & PARSE_OPT_OPTARG)\n-\t\t\t\t\tif (opts->long_name)\n-\t\t\t\t\t\tpos += fprintf(stderr, \"[=...]\");\n-\t\t\t\t\telse\n-\t\t\t\t\t\tpos += fprintf(stderr, \"[...]\");\n-\t\t\t\telse\n-\t\t\t\t\tpos += fprintf(stderr, \" ...\");\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tdefault: /* OPTION_{BIT,BOOLEAN,NUMBER,SET_INT,SET_PTR} */\n-\t\t\tbreak;\n-\t\t}\n+\t\tif (!(opts->flags & PARSE_OPT_NOARG))\n+\t\t\tpos += usage_argh(opts);\n \n \t\tif (pos <= USAGE_OPTS_WIDTH)\n \t\t\tpad = USAGE_OPTS_WIDTH - pos;\ndiff --git a/parse-options.h b/parse-options.h\nindex b141ae6..f65aca3 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -67,7 +67,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);\n  * `flags`::\n  *   mask of parse_opt_option_flags.\n  *   PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)\n- *   PARSE_OPT_NOARG: says that this option takes no argument, for CALLBACKs\n+ *   PARSE_OPT_NOARG: says that this option takes no argument\n  *   PARSE_OPT_NONEG: says that this option cannot be negated\n  *   PARSE_OPT_HIDDEN: this option is skipped in the default usage, and\n  *                     shown only in the full usage.\n@@ -101,13 +101,19 @@ struct option {\n };\n \n #define OPT_END()                   { OPTION_END }\n-#define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, (h) }\n+#define OPT_ARGUMENT(l, h)          { OPTION_ARGUMENT, 0, (l), NULL, NULL, \\\n+\t\t\t\t      (h), PARSE_OPT_NOARG}\n #define OPT_GROUP(h)                { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }\n-#define OPT_BIT(s, l, v, h, b)      { OPTION_BIT, (s), (l), (v), NULL, (h), 0, NULL, (b) }\n-#define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, (h), 0, NULL, (b) }\n-#define OPT_BOOLEAN(s, l, v, h)     { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) }\n-#define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) }\n-#define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }\n+#define OPT_BIT(s, l, v, h, b)      { OPTION_BIT, (s), (l), (v), NULL, (h), \\\n+\t\t\t\t      PARSE_OPT_NOARG, NULL, (b) }\n+#define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \\\n+\t\t\t\t      (h), PARSE_OPT_NOARG, NULL, (b) }\n+#define OPT_BOOLEAN(s, l, v, h)     { OPTION_BOOLEAN, (s), (l), (v), NULL, \\\n+\t\t\t\t      (h), PARSE_OPT_NOARG }\n+#define OPT_SET_INT(s, l, v, h, i)  { OPTION_SET_INT, (s), (l), (v), NULL, \\\n+\t\t\t\t      (h), PARSE_OPT_NOARG, NULL, (i) }\n+#define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \\\n+\t\t\t\t      (h), PARSE_OPT_NOARG, NULL, (p) }\n #define OPT_INTEGER(s, l, v, h)     { OPTION_INTEGER, (s), (l), (v), \"n\", (h) }\n #define OPT_STRING(s, l, v, a, h)   { OPTION_STRING,  (s), (l), (v), (a), (h) }\n #define OPT_DATE(s, l, v, h) \\\n-- \n1.6.3.1.266.gb11cf\n"},{"id":"115639","messageId":"4A2A453B.7060202@lsrfire.ath.cx","threadId":"19648","inReplyTo":"1244159037-9292-2-git-send-email-bebarino@gmail.com","subject":"Re: [PATCHv2 2/2] parse-options: simplify usage argh handling","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-06-06T10:30:19Z","receivedAt":"2009-06-06T10:30:19Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Stephen Boyd schrieb:\n> Simplify the argh printing by simply calling usage_argh() if the option\n> can take an argument. Update macros defined in parse-options.h to set\n> the PARSE_OPT_NOARG flag.\n> \n> The only other user of custom non-argument taking options is git-apply\n> (in this case OPTION_BOOLEAN for deprecated options). Update it to set\n> the PARSE_OPT_NOARG flag.\n> \n> Thanks to René Scharfe for the suggestion and starter patch.\n> \n> Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n> ---\n> \n> René, feel free to signoff if you like.\n> \n>  builtin-apply.c |    6 ++++--\n>  parse-options.c |   33 ++++-----------------------------\n>  parse-options.h |   20 +++++++++++++-------\n>  3 files changed, 21 insertions(+), 38 deletions(-)\n\nLooks good, thanks.  The output of this command:\n\n\t$ for c in ./git-*; do $c --help-all </dev/null; done\n\ndidn't change, except for git-send-email reporting a different temporary\nfile name (unrelated to this patch, of course).\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n"}]}