{"thread":{"id":"21644","subject":"[PATCH v3] git remote: Separate usage strings for subcommands","startedAt":"2009-11-17T02:23:27Z","lastAt":"2009-11-17T02:23:27Z","messageCount":1,"participants":["Tim Henigan"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"127725","messageId":"4B02091F.7020504@gmail.com","threadId":"21644","inReplyTo":null,"subject":"[PATCH v3] git remote: Separate usage strings for subcommands","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2009-11-17T02:23:27Z","receivedAt":"2009-11-17T02:23:27Z","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 options from the first line\nof the usage string (replacing them with '<options>...'\nand lets them be documented in the paragraph below.\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\nAll usage strings are still only located at the top of file.  However,\nseparate usage string arrays have been created for each subcommand.\n\nv2 fixed line wrap issues present in v1.\n\nv3 changes include:\n  - Changed usage strings to use '<options>...' rather than document\n    the options both in the actual string and in the OPT_x array\n    (as recommended by Junio).\n  - Removed the change made to the usage string array constructed\n    in 'cmd_remote'. v2 was broken because that change had made\n    the command stop recognizing the '-v' option. Added an extra\n    note here which explains that '-v' is only valid when placed\n    after 'git remote' and before any 'subcommand'.\n  - Updated the man page.\n\n\n Documentation/git-remote.txt |   13 +++++----\n builtin-remote.c             |   58 ++++++++++++++++++++++++++----------------\n 2 files changed, 43 insertions(+), 28 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 82a3d29..c84265a 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -9,14 +9,14 @@ git-remote - manage set of tracked repositories\n SYNOPSIS\n --------\n [verse]\n-'git remote' [-v | --verbose]\n-'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\n+'git remote' [<options>...]\n+'git remote add' [<options>...] <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 prune' [-n | --dry-run] <name>\n-'git remote update' [-p | --prune] [group | remote]...\n+'git remote set-head' <name> [<options>...]\n+'git remote show' [<options>...] <name>\n+'git remote prune' [<options>...] <name>\n+'git remote update' [<options>...] [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..ee86810 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -7,18 +7,35 @@\n #include \"run-command.h\"\n #include \"refs.h\"\n \n+#define REMOTE_BARE_USAGE \"git remote [<options>...]\"\n+#define REMOTE_ADD_USAGE \"git remote add [<options>...] <name> <url>\"\n+#define REMOTE_RENAME_USAGE \"git remote rename <old> <new>\"\n+#define REMOTE_RM_USAGE \"git remote rm <name>\"\n+#define REMOTE_SETHEAD_USAGE \"git remote set-head <name> [<options>...]\"\n+#define REMOTE_SHOW_USAGE \"git remote show [<options>...] <name>\"\n+#define REMOTE_PRUNE_USAGE \"git remote prune [<options>...] <name>\"\n+#define REMOTE_UPDATE_USAGE \"git remote update [<options>...]\"\n+\n static const char * const builtin_remote_usage[] = {\n-\t\"git remote [-v | --verbose]\",\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 prune [-n | --dry-run] <name>\",\n-\t\"git remote [-v | --verbose] update [-p | --prune] [group]\",\n+\tREMOTE_BARE_USAGE,\n+\tREMOTE_ADD_USAGE,\n+\tREMOTE_RENAME_USAGE,\n+\tREMOTE_RM_USAGE,\n+\tREMOTE_SETHEAD_USAGE,\n+\tREMOTE_SHOW_USAGE,\n+\tREMOTE_PRUNE_USAGE,\n+\tREMOTE_UPDATE_USAGE,\n \tNULL\n };\n \n+static const char * const builtin_remote_add_usage[] = { REMOTE_ADD_USAGE, NULL };\n+static const char * const builtin_remote_rename_usage[] = { REMOTE_RENAME_USAGE, NULL };\n+static const char * const builtin_remote_rm_usage[] = { REMOTE_RM_USAGE, NULL };\n+static const char * const builtin_remote_sethead_usage[] = { REMOTE_SETHEAD_USAGE, NULL };\n+static const char * const builtin_remote_show_usage[] = { REMOTE_SHOW_USAGE, NULL };\n+static const char * const builtin_remote_prune_usage[] = { REMOTE_PRUNE_USAGE, NULL };\n+static const char * const builtin_remote_update_usage[] = { REMOTE_UPDATE_USAGE, NULL };\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 +87,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 +95,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 +556,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 +697,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@@ -984,7 +1000,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@@ -1088,7 +1104,7 @@ static int set_head(int argc, const char **argv)\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 +1130,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 +1154,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 +1243,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 +1348,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.g868bf.dirty\n"}]}