{"thread":{"id":"21642","subject":"[PATCH RFC v2] git remote: Separate usage strings for subcommands","startedAt":"2009-11-17T00:59:07Z","lastAt":"2009-11-17T00:59:07Z","messageCount":1,"participants":["Tim Henigan"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"127721","messageId":"4B01F55B.8050304@gmail.com","threadId":"21642","inReplyTo":null,"subject":"[PATCH RFC v2] git remote: Separate usage strings for subcommands","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2009-11-17T00:59:07Z","receivedAt":"2009-11-17T00:59:07Z","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\nSigned-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n\nThis is a resend -- v1 had line wrap issues.  Sorry for the noise.\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\nDoes this look like a sane way to structure the code?\n\n\n builtin-remote.c |   57 +++++++++++++++++++++++++++++++++--------------------\n 1 files changed, 35 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex 0777dd7..ec65a4b 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\t\"git remote [-v | --verbose]\"\n+#define REMOTE_ADD_USAGE\t\"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>\"\n+#define REMOTE_RENAME_USAGE\t\"git remote rename <old> <new>\"\n+#define REMOTE_RM_USAGE\t\t\"git remote rm <name>\"\n+#define REMOTE_SETHEAD_USAGE\t\"git remote set-head <name> [-a | -d | <branch>]\"\n+#define REMOTE_SHOW_USAGE\t\"git remote show [-n] <name>\"\n+#define REMOTE_PRUNE_USAGE\t\"git remote prune [-n | --dry-run] <name>\"\n+#define REMOTE_UPDATE_USAGE\t\"git remote [-v | --verbose] update [-p | --prune] [group]\"\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,6 @@ 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_END()\n \t};\n \tint result;\n-- 1.6.5.2.185.gb7fba.dirty \n"}]}