{"thread":{"id":"21693","subject":"[PATCH v5] git remote: Separate usage strings for subcommands","startedAt":"2009-11-20T23:43:13Z","lastAt":"2009-11-20T23:43:13Z","messageCount":1,"participants":["Tim Henigan"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"128057","messageId":"4B072991.1090401@gmail.com","threadId":"21693","inReplyTo":null,"subject":"[PATCH v5] git remote: Separate usage strings for subcommands","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2009-11-20T23:43:13Z","receivedAt":"2009-11-20T23:43:13Z","isPatch":true,"sender":{"key":"tim.henigan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42022?v=4"},"body":"When the usage string for a subcommand must be printed,\nonly print the information relevant to that command.\n\nThis commit also removes the complete options list from\nthe first line of the subcommand usage string. Instead,\nindividual options are documented in the detailed\ndescription following the general usage line.\n\nSigned-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n\nThis patch is based on:\nhttp://article.gmane.org/gmane.comp.version-control.git/132953\n\nAfter some misunderstanding on my part, this version of the patch\nshould be correct.  The following snippet [1] explains the intent:\n\n> Junio C Hamano wrote:\n>> Tim Henigan <tim.henigan@gmail.com> writes:\n>> \n>> Using the 'add' subcommand as an example, the desired output is:\n>>\n>> Output of 'git remote -h':\n>>     \"git remote [-v | --verbose]\"\n>>     \"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\"\n>>     etc.\n>>\n>> Output of 'git remote add -h':\n>>     \"git remote add [<options>...] <name> <url>\"\n>>     followed by the detailed description given by 'parse_options()'.\n>>\n>> Text in 'man git-remote':\n>>     \"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\"\n>>     with the options explained in detail later in the file.\n>>\n>> Thanks for your patience,\n> \n> I think the above looks good;\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/133209/focus=133243\n\n\n Documentation/git-remote.txt |    7 ++--\n builtin-remote.c             |   66 ++++++++++++++++++++++++++++++-----------\n 2 files changed, 52 insertions(+), 21 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 82a3d29..c272c92 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -13,10 +13,10 @@ SYNOPSIS\n 'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\n 'git remote rename' <old> <new>\n 'git remote rm' <name>\n-'git remote set-head' <name> [-a | -d | <branch>]\n-'git remote show' [-n] <name>\n+'git remote set-head' <name> (-a | -d | <branch>)\n+'git remote' [-v | --verbose] 'show' [-n] <name>\n 'git remote prune' [-n | --dry-run] <name>\n-'git remote update' [-p | --prune] [group | remote]...\n+'git remote' [-v | --verbose] 'update' [-p | --prune] [group | remote]...\n \n DESCRIPTION\n -----------\n@@ -30,6 +30,7 @@ OPTIONS\n -v::\n --verbose::\n \tBe a little more verbose and show remote url after name.\n+\tNOTE: This must be placed between `remote` and `subcommand`.\n \n \n COMMANDS\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex 0777dd7..4f4cba4 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -12,13 +12,48 @@ static const char * const builtin_remote_usage[] = {\n \t\"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\",\n \t\"git remote rename <old> <new>\",\n \t\"git remote rm <name>\",\n-\t\"git remote set-head <name> [-a | -d | <branch>]\",\n-\t\"git remote show [-n] <name>\",\n+\t\"git remote set-head <name> (-a | -d | <branch>)\",\n+\t\"git remote [-v | --verbose] show [-n] <name>\",\n \t\"git remote prune [-n | --dry-run] <name>\",\n \t\"git remote [-v | --verbose] update [-p | --prune] [group]\",\n \tNULL\n };\n \n+static const char * const builtin_remote_add_usage[] = {\n+\t\"git remote add [<options>] <name> <url>\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_rename_usage[] = {\n+\t\"git remote rename <old> <new>\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_rm_usage[] = {\n+\t\"git remote rm <name>\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_sethead_usage[] = {\n+\t\"git remote set-head <name> (-a | -d | <branch>])\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_show_usage[] = {\n+\t\"git remote show [<options>] <name>\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_prune_usage[] = {\n+\t\"git remote prune [<options>] <name>\",\n+\tNULL\n+};\n+\n+static const char * const builtin_remote_update_usage[] = {\n+\t\"git remote update [<options>] [<group> | <remote>]...\",\n+\tNULL\n+};\n+\n #define GET_REF_STATES (1<<0)\n #define GET_HEAD_NAMES (1<<1)\n #define GET_PUSH_REF_STATES (1<<2)\n@@ -70,7 +105,6 @@ static int add(int argc, const char **argv)\n \tint i;\n \n \tstruct option options[] = {\n-\t\tOPT_GROUP(\"add specific options\"),\n \t\tOPT_BOOLEAN('f', \"fetch\", &fetch, \"fetch the remote branches\"),\n \t\tOPT_CALLBACK('t', \"track\", &track, \"branch\",\n \t\t\t\"branch(es) to track\", opt_parse_track),\n@@ -79,11 +113,11 @@ static int add(int argc, const char **argv)\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n+\targc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage,\n \t\t\t     0);\n \n \tif (argc < 2)\n-\t\tusage_with_options(builtin_remote_usage, options);\n+\t\tusage_with_options(builtin_remote_add_usage, options);\n \n \tname = argv[0];\n \turl = argv[1];\n@@ -540,7 +574,7 @@ static int mv(int argc, const char **argv)\n \tint i;\n \n \tif (argc != 3)\n-\t\tusage_with_options(builtin_remote_usage, options);\n+\t\tusage_with_options(builtin_remote_rename_usage, options);\n \n \trename.old = argv[1];\n \trename.new = argv[2];\n@@ -681,7 +715,7 @@ static int rm(int argc, const char **argv)\n \tint i, result;\n \n \tif (argc != 2)\n-\t\tusage_with_options(builtin_remote_usage, options);\n+\t\tusage_with_options(builtin_remote_rm_usage, options);\n \n \tremote = remote_get(argv[1]);\n \tif (!remote)\n@@ -976,7 +1010,6 @@ static int show(int argc, const char **argv)\n {\n \tint no_query = 0, result = 0, query_flag = 0;\n \tstruct option options[] = {\n-\t\tOPT_GROUP(\"show specific options\"),\n \t\tOPT_BOOLEAN('n', NULL, &no_query, \"do not query remotes\"),\n \t\tOPT_END()\n \t};\n@@ -984,7 +1017,7 @@ static int show(int argc, const char **argv)\n \tstruct string_list info_list = { NULL, 0, 0, 0 };\n \tstruct show_info info;\n \n-\targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n+\targc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,\n \t\t\t     0);\n \n \tif (argc < 1)\n@@ -1081,14 +1114,13 @@ static int set_head(int argc, const char **argv)\n \tchar *head_name = NULL;\n \n \tstruct option options[] = {\n-\t\tOPT_GROUP(\"set-head specific options\"),\n \t\tOPT_BOOLEAN('a', \"auto\", &opt_a,\n \t\t\t    \"set refs/remotes/<name>/HEAD according to remote\"),\n \t\tOPT_BOOLEAN('d', \"delete\", &opt_d,\n \t\t\t    \"delete refs/remotes/<name>/HEAD\"),\n \t\tOPT_END()\n \t};\n-\targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n+\targc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage,\n \t\t\t     0);\n \tif (argc)\n \t\tstrbuf_addf(&buf, \"refs/remotes/%s/HEAD\", argv[0]);\n@@ -1114,7 +1146,7 @@ static int set_head(int argc, const char **argv)\n \t\tif (delete_ref(buf.buf, NULL, REF_NODEREF))\n \t\t\tresult |= error(\"Could not delete %s\", buf.buf);\n \t} else\n-\t\tusage_with_options(builtin_remote_usage, options);\n+\t\tusage_with_options(builtin_remote_sethead_usage, options);\n \n \tif (head_name) {\n \t\tunsigned char sha1[20];\n@@ -1138,16 +1170,15 @@ static int prune(int argc, const char **argv)\n {\n \tint dry_run = 0, result = 0;\n \tstruct option options[] = {\n-\t\tOPT_GROUP(\"prune specific options\"),\n \t\tOPT__DRY_RUN(&dry_run),\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n+\targc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,\n \t\t\t     0);\n \n \tif (argc < 1)\n-\t\tusage_with_options(builtin_remote_usage, options);\n+\t\tusage_with_options(builtin_remote_prune_usage, options);\n \n \tfor (; argc; argc--, argv++)\n \t\tresult |= prune_remote(*argv, dry_run);\n@@ -1228,13 +1259,12 @@ static int update(int argc, const char **argv)\n \tstruct string_list list = { NULL, 0, 0, 0 };\n \tstatic const char *default_argv[] = { NULL, \"default\", NULL };\n \tstruct option options[] = {\n-\t\tOPT_GROUP(\"update specific options\"),\n \t\tOPT_BOOLEAN('p', \"prune\", &prune,\n \t\t\t    \"prune remotes after fetching\"),\n \t\tOPT_END()\n \t};\n \n-\targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n+\targc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,\n \t\t\t     PARSE_OPT_KEEP_ARGV0);\n \tif (argc < 2) {\n \t\targc = 2;\n@@ -1334,7 +1364,7 @@ static int show_all(void)\n int cmd_remote(int argc, const char **argv, const char *prefix)\n {\n \tstruct option options[] = {\n-\t\tOPT__VERBOSE(&verbose),\n+\t\tOPT_BOOLEAN('v', \"verbose\", &verbose, \"be verbose; must be placed before a subcommand\"),\n \t\tOPT_END()\n \t};\n \tint result;\n-- \n1.6.5.2.186.g3ccc3\n"}]}