@matheusbsbs / matheus-bagliano / commits / 4504107d5e
Fork 0

git remote: Separate usage strings for subcommands

When the usage string for a subcommand must be printed, only print the information relevant to that command. This commit also removes the complete options list from the first line of the subcommand usage string. Instead, individual options are documented in the detailed description following the general usage line. Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tim Henigan committed Nov 20, 2009 at 18:43 UTC 4504107d5ef6a8840aaf278e63722bf4efbf722e
2 files changed +52 -21
Documentation/git-remote.txt
+4 -3
@@ -13,10 +13,10 @@ SYNOPSIS
13 'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
14 'git remote rename' <old> <new>
15 'git remote rm' <name>
16 -'git remote set-head' <name> [-a | -d | <branch>]
17 -'git remote show' [-n] <name>
16 +'git remote set-head' <name> (-a | -d | <branch>)
17 +'git remote' [-v | --verbose] 'show' [-n] <name>
18 'git remote prune' [-n | --dry-run] <name>
19 -'git remote update' [-p | --prune] [group | remote]...
19 +'git remote' [-v | --verbose] 'update' [-p | --prune] [group | remote]...
20
21 DESCRIPTION
22 -----------
@@ -30,6 +30,7 @@ OPTIONS
30 -v::
31 --verbose::
32 Be a little more verbose and show remote url after name.
33 + NOTE: This must be placed between `remote` and `subcommand`.
34
35
36 COMMANDS
builtin-remote.c
+48 -18
@@ -12,13 +12,48 @@ static const char * const builtin_remote_usage[] = {
12 "git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>",
13 "git remote rename <old> <new>",
14 "git remote rm <name>",
15 - "git remote set-head <name> [-a | -d | <branch>]",
16 - "git remote show [-n] <name>",
15 + "git remote set-head <name> (-a | -d | <branch>)",
16 + "git remote [-v | --verbose] show [-n] <name>",
17 "git remote prune [-n | --dry-run] <name>",
18 "git remote [-v | --verbose] update [-p | --prune] [group]",
19 NULL
20 };
21
22 +static const char * const builtin_remote_add_usage[] = {
23 + "git remote add [<options>] <name> <url>",
24 + NULL
25 +};
26 +
27 +static const char * const builtin_remote_rename_usage[] = {
28 + "git remote rename <old> <new>",
29 + NULL
30 +};
31 +
32 +static const char * const builtin_remote_rm_usage[] = {
33 + "git remote rm <name>",
34 + NULL
35 +};
36 +
37 +static const char * const builtin_remote_sethead_usage[] = {
38 + "git remote set-head <name> (-a | -d | <branch>])",
39 + NULL
40 +};
41 +
42 +static const char * const builtin_remote_show_usage[] = {
43 + "git remote show [<options>] <name>",
44 + NULL
45 +};
46 +
47 +static const char * const builtin_remote_prune_usage[] = {
48 + "git remote prune [<options>] <name>",
49 + NULL
50 +};
51 +
52 +static const char * const builtin_remote_update_usage[] = {
53 + "git remote update [<options>] [<group> | <remote>]...",
54 + NULL
55 +};
56 +
57 #define GET_REF_STATES (1<<0)
58 #define GET_HEAD_NAMES (1<<1)
59 #define GET_PUSH_REF_STATES (1<<2)
@@ -70,7 +105,6 @@ static int add(int argc, const char **argv)
105 int i;
106
107 struct option options[] = {
73 - OPT_GROUP("add specific options"),
108 OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
109 OPT_CALLBACK('t', "track", &track, "branch",
110 "branch(es) to track", opt_parse_track),
@@ -79,11 +113,11 @@ static int add(int argc, const char **argv)
113 OPT_END()
114 };
115
82 - argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
116 + argc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage,
117 0);
118
119 if (argc < 2)
86 - usage_with_options(builtin_remote_usage, options);
120 + usage_with_options(builtin_remote_add_usage, options);
121
122 name = argv[0];
123 url = argv[1];
@@ -540,7 +574,7 @@ static int mv(int argc, const char **argv)
574 int i;
575
576 if (argc != 3)
543 - usage_with_options(builtin_remote_usage, options);
577 + usage_with_options(builtin_remote_rename_usage, options);
578
579 rename.old = argv[1];
580 rename.new = argv[2];
@@ -681,7 +715,7 @@ static int rm(int argc, const char **argv)
715 int i, result;
716
717 if (argc != 2)
684 - usage_with_options(builtin_remote_usage, options);
718 + usage_with_options(builtin_remote_rm_usage, options);
719
720 remote = remote_get(argv[1]);
721 if (!remote)
@@ -976,7 +1010,6 @@ static int show(int argc, const char **argv)
1010 {
1011 int no_query = 0, result = 0, query_flag = 0;
1012 struct option options[] = {
979 - OPT_GROUP("show specific options"),
1013 OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
1014 OPT_END()
1015 };
@@ -984,7 +1017,7 @@ static int show(int argc, const char **argv)
1017 struct string_list info_list = { NULL, 0, 0, 0 };
1018 struct show_info info;
1019
987 - argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1020 + argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
1021 0);
1022
1023 if (argc < 1)
@@ -1081,14 +1114,13 @@ static int set_head(int argc, const char **argv)
1114 char *head_name = NULL;
1115
1116 struct option options[] = {
1084 - OPT_GROUP("set-head specific options"),
1117 OPT_BOOLEAN('a', "auto", &opt_a,
1118 "set refs/remotes/<name>/HEAD according to remote"),
1119 OPT_BOOLEAN('d', "delete", &opt_d,
1120 "delete refs/remotes/<name>/HEAD"),
1121 OPT_END()
1122 };
1091 - argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1123 + argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage,
1124 0);
1125 if (argc)
1126 strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
@@ -1114,7 +1146,7 @@ static int set_head(int argc, const char **argv)
1146 if (delete_ref(buf.buf, NULL, REF_NODEREF))
1147 result |= error("Could not delete %s", buf.buf);
1148 } else
1117 - usage_with_options(builtin_remote_usage, options);
1149 + usage_with_options(builtin_remote_sethead_usage, options);
1150
1151 if (head_name) {
1152 unsigned char sha1[20];
@@ -1138,16 +1170,15 @@ static int prune(int argc, const char **argv)
1170 {
1171 int dry_run = 0, result = 0;
1172 struct option options[] = {
1141 - OPT_GROUP("prune specific options"),
1173 OPT__DRY_RUN(&dry_run),
1174 OPT_END()
1175 };
1176
1146 - argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1177 + argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,
1178 0);
1179
1180 if (argc < 1)
1150 - usage_with_options(builtin_remote_usage, options);
1181 + usage_with_options(builtin_remote_prune_usage, options);
1182
1183 for (; argc; argc--, argv++)
1184 result |= prune_remote(*argv, dry_run);
@@ -1228,13 +1259,12 @@ static int update(int argc, const char **argv)
1259 struct string_list list = { NULL, 0, 0, 0 };
1260 static const char *default_argv[] = { NULL, "default", NULL };
1261 struct option options[] = {
1231 - OPT_GROUP("update specific options"),
1262 OPT_BOOLEAN('p', "prune", &prune,
1263 "prune remotes after fetching"),
1264 OPT_END()
1265 };
1266
1237 - argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1267 + argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
1268 PARSE_OPT_KEEP_ARGV0);
1269 if (argc < 2) {
1270 argc = 2;
@@ -1334,7 +1364,7 @@ static int show_all(void)
1364 int cmd_remote(int argc, const char **argv, const char *prefix)
1365 {
1366 struct option options[] = {
1337 - OPT__VERBOSE(&verbose),
1367 + OPT_BOOLEAN('v', "verbose", &verbose, "be verbose; must be placed before a subcommand"),
1368 OPT_END()
1369 };
1370 int result;