{"thread":{"id":"10924","subject":"[PATCH/RFC] parse-options: allow to define hidden synonym options","startedAt":"2007-11-19T06:09:41Z","lastAt":"2007-11-19T09:22:07Z","messageCount":3,"participants":["Junio C Hamano","Pierre Habouzit"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60267","messageId":"7v4pfircka.fsf@gitster.siamese.dyndns.org","threadId":"10924","inReplyTo":null,"subject":"[PATCH/RFC] parse-options: allow to define hidden synonym options","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-19T06:09:41Z","receivedAt":"2007-11-19T06:09:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"By setting the help member to NULL, you can implement an option\nthat is not shown in the \"git-cmd -h\" help output.  This is\nuseful to support backward compatible synonyms without\ncluttering the help text.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n parse-options.c |    2 ++\n parse-options.h |    2 +-\n 2 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex d3e608a..1ee2c81 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -284,6 +284,8 @@ void usage_with_options(const char * const *usagestr,\n \t\t\tif (*opts->help)\n \t\t\t\tfprintf(stderr, \"%s\\n\", opts->help);\n \t\t\tcontinue;\n+\t\t} else if (!opts->help) {\n+\t\t\tcontinue;\n \t\t}\n \n \t\tpos = fprintf(stderr, \"    \");\ndiff --git a/parse-options.h b/parse-options.h\nindex a8760ac..de249a0 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -49,7 +49,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);\n  *\n  * `help`::\n  *   the short help associated to what the option does.\n- *   Must never be NULL (except for OPTION_END).\n+ *   option with this field set to NULL does not appear in the help listing.\n  *   OPTION_GROUP uses this pointer to store the group header.\n  *\n  * `flags`::\n-- \n1.5.3.6.1779.ga3ed\n"},{"id":"60274","messageId":"7vsl32oe48.fsf@gitster.siamese.dyndns.org","threadId":"10924","inReplyTo":"7v4pfircka.fsf@gitster.siamese.dyndns.org","subject":"[PATCH Illustration] branch --contains=<commit>","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-19T08:04:23Z","receivedAt":"2007-11-19T08:04:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This renames the --with=<commit> option to --contains=<commit>, but still\nsupports the earlier --with=<commit> variant as a hidden synonym.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * An example usage of the \".help = NULL\" member in the options\n   structure.\n\n builtin-branch.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex fd36e4f..5dc0c57 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -562,9 +562,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOLEAN( 0 , \"color\",  &branch_use_color, \"use colored output\"),\n \t\tOPT_SET_INT('r', NULL,     &kinds, \"act on remote-tracking branches\",\n \t\t\tREF_REMOTE_BRANCH),\n-\t\tOPT_CALLBACK(0, \"with\",    &with_commit, \"commit\",\n+\t\tOPT_CALLBACK(0, \"contains\",&with_commit, \"commit\",\n \t\t\t     \"print only branches that contain the commit\",\n \t\t\t     opt_parse_with_commit),\n+\t\tOPT_CALLBACK(0, \"with\",    &with_commit, \"commit\",\n+\t\t\t     NULL,\n+\t\t\t     opt_parse_with_commit),\n \t\tOPT__ABBREV(&abbrev),\n \n \t\tOPT_GROUP(\"Specific git-branch actions:\"),\n-- \n1.5.3.6.1788.gcc5c4\n"},{"id":"60280","messageId":"20071119092207.GB9028@artemis.corp","threadId":"10924","inReplyTo":"7v4pfircka.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH/RFC] parse-options: allow to define hidden synonym options","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2007-11-19T09:22:07Z","receivedAt":"2007-11-19T09:22:07Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On lun, nov 19, 2007 at 06:09:41 +0000, Junio C Hamano wrote:\n> By setting the help member to NULL, you can implement an option\n> that is not shown in the \"git-cmd -h\" help output.  This is\n> useful to support backward compatible synonyms without\n> cluttering the help text.\n\n  Sorry I'm not very present those days, but oh well...\n\n  The idea looks nice, though if we are doing this, I'd like to see it\nfix other problems at the same time. We sometimes have \"internal\"\ncommands switches and other cases of alias.\n\n  I wonder if it wouldn't be better that we have some kind of --help-all\nswitch that would show them _all_ and a way (through another flag ?) to\nhide those additional options by default.\n\n  And defining an alias would then be:\n\n  { OPTION_SOME_TYPE, 0, \"alias-name\", &some_value, \"some-arg\",\n    \"backward compatibility alias for \\\"foo\\\"\", PARSE_OPT_HIDE, ... }\n\nor:\n\n  { OPTION_SOME_TYPE, 0, \"plumbing-dark-think\", &some_value, \"some-arg\",\n    \"internal plumbing switch used in\", PARSE_OPT_HIDE, ... }\n\n\n  I personnaly don't like that parse-opt sees more options than what it\nsays it sees, else with your patch, if the user gives ambiguous\nabbreviated long switches, he'll get \"--w is ambiguous, could be\n`--whith` or `--wibble`\" whereas he never knew that --with existed in\nthe first place.\n\n  That gives something more along the lines of :\n\nFrom 860a5bf335e44dd2bbe5f30620c99d174b697f69 Mon Sep 17 00:00:00 2001\nFrom: Pierre Habouzit <madcoder@debian.org>\nDate: Mon, 19 Nov 2007 10:21:44 +0100\nSubject: [PATCH] parse-options: Allow to hide options from the default usage.\n\nThis is useful for backward-compatibility aliases, or very advanced command\nline switches introduced for internal git usages and have no real use for a\nuser.\n\nparse-options still shows them if the user asks for --help-all.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n parse-options.c |   17 +++++++++++++++--\n parse-options.h |    3 +++\n 2 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex d3e608a..807e443 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -216,6 +216,9 @@ is_abbreviated:\n \treturn error(\"unknown option `%s'\", arg);\n }\n \n+static NORETURN void usage_with_options_internal(const char * const *,\n+                                                 const struct option *, int);\n+\n int parse_options(int argc, const char **argv, const struct option *options,\n                   const char * const usagestr[], int flags)\n {\n@@ -249,6 +252,8 @@ int parse_options(int argc, const char **argv, const struct option *options,\n \t\t\tbreak;\n \t\t}\n \n+\t\tif (!strcmp(arg + 2, \"help-all\"))\n+\t\t\tusage_with_options_internal(usagestr, options, 1);\n \t\tif (!strcmp(arg + 2, \"help\"))\n \t\t\tusage_with_options(usagestr, options);\n \t\tif (parse_long_opt(&args, arg + 2, options))\n@@ -263,8 +268,8 @@ int parse_options(int argc, const char **argv, const struct option *options,\n #define USAGE_OPTS_WIDTH 24\n #define USAGE_GAP         2\n \n-void usage_with_options(const char * const *usagestr,\n-                        const struct option *opts)\n+void usage_with_options_internal(const char * const *usagestr,\n+                                 const struct option *opts, int full)\n {\n \tfprintf(stderr, \"usage: %s\\n\", *usagestr++);\n \twhile (*usagestr && **usagestr)\n@@ -285,6 +290,8 @@ void usage_with_options(const char * const *usagestr,\n \t\t\t\tfprintf(stderr, \"%s\\n\", opts->help);\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!full & (opts->flags & PARSE_OPT_HIDDEN))\n+\t\t\tcontinue;\n \n \t\tpos = fprintf(stderr, \"    \");\n \t\tif (opts->short_name)\n@@ -335,6 +342,12 @@ void usage_with_options(const char * const *usagestr,\n \texit(129);\n }\n \n+void usage_with_options(const char * const *usagestr,\n+                        const struct option *opts)\n+{\n+\tusage_with_options_internal(usagestr, opts, 0);\n+}\n+\n /*----- some often used options -----*/\n #include \"cache.h\"\n \ndiff --git a/parse-options.h b/parse-options.h\nindex a8760ac..102ac31 100644\n--- a/parse-options.h\n+++ b/parse-options.h\n@@ -24,6 +24,7 @@ enum parse_opt_option_flags {\n \tPARSE_OPT_OPTARG  = 1,\n \tPARSE_OPT_NOARG   = 2,\n \tPARSE_OPT_NONEG   = 4,\n+\tPARSE_OPT_HIDDEN  = 8,\n };\n \n struct option;\n@@ -57,6 +58,8 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);\n  *   PARSE_OPT_OPTARG: says that the argument is optionnal (not for BOOLEANs)\n  *   PARSE_OPT_NOARG: says that this option takes no argument, for CALLBACKs\n  *   PARSE_OPT_NONEG: says that this option cannot be negated\n+ *   PARSE_OPT_HIDDEN this option is skipped in the default usage, showed in\n+ *                    the long one.\n  *\n  * `callback`::\n  *   pointer to the callback to use for OPTION_CALLBACK.\n-- \n1.5.3.5.1795.g5421e-dirty\n\n"}]}