Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * builtin-help.c |
| 3 | * |
| 4 | * Builtin help-related commands (help, usage, version) |
| 5 | */ |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 6 | #include "cache.h" |
| 7 | #include "builtin.h" |
| 8 | #include "exec_cmd.h" |
| 9 | #include "common-cmds.h" |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 10 | #include "parse-options.h" |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 11 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 12 | enum help_format { |
| 13 | HELP_FORMAT_MAN, |
| 14 | HELP_FORMAT_INFO, |
| 15 | HELP_FORMAT_WEB, |
| 16 | }; |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 17 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 18 | static int show_all = 0; |
| 19 | static enum help_format help_format = HELP_FORMAT_MAN; |
| 20 | static struct option builtin_help_options[] = { |
| 21 | OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), |
| 22 | OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), |
| 23 | OPT_SET_INT('w', "web", &help_format, "show manual in web browser", |
| 24 | HELP_FORMAT_WEB), |
| 25 | OPT_SET_INT('i', "info", &help_format, "show info page", |
| 26 | HELP_FORMAT_INFO), |
| 27 | }; |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 28 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 29 | static const char * const builtin_help_usage[] = { |
| 30 | "git-help [--all] [--man|--web|--info] [command]", |
| 31 | NULL |
| 32 | }; |
| 33 | |
| 34 | static enum help_format parse_help_format(const char *format) |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 35 | { |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 36 | if (!strcmp(format, "man")) |
| 37 | return HELP_FORMAT_MAN; |
| 38 | if (!strcmp(format, "info")) |
| 39 | return HELP_FORMAT_INFO; |
| 40 | if (!strcmp(format, "web") || !strcmp(format, "html")) |
| 41 | return HELP_FORMAT_WEB; |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 42 | die("unrecognized help format '%s'", format); |
| 43 | } |
| 44 | |
| 45 | static int git_help_config(const char *var, const char *value) |
| 46 | { |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 47 | if (!strcmp(var, "help.format")) { |
| 48 | if (!value) |
| 49 | return config_error_nonbool(var); |
| 50 | help_format = parse_help_format(value); |
| 51 | return 0; |
| 52 | } |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 53 | return git_default_config(var, value); |
| 54 | } |
| 55 | |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 56 | /* most GUI terminals set COLUMNS (although some don't export it) */ |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 57 | static int term_columns(void) |
| 58 | { |
| 59 | char *col_string = getenv("COLUMNS"); |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 60 | int n_cols; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 61 | |
| 62 | if (col_string && (n_cols = atoi(col_string)) > 0) |
| 63 | return n_cols; |
| 64 | |
| 65 | #ifdef TIOCGWINSZ |
| 66 | { |
| 67 | struct winsize ws; |
| 68 | if (!ioctl(1, TIOCGWINSZ, &ws)) { |
| 69 | if (ws.ws_col) |
| 70 | return ws.ws_col; |
| 71 | } |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | return 80; |
| 76 | } |
| 77 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 78 | static inline void mput_char(char c, unsigned int num) |
| 79 | { |
| 80 | while(num--) |
| 81 | putchar(c); |
| 82 | } |
| 83 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 84 | static struct cmdnames { |
| 85 | int alloc; |
| 86 | int cnt; |
| 87 | struct cmdname { |
| 88 | size_t len; |
| 89 | char name[1]; |
| 90 | } **names; |
| 91 | } main_cmds, other_cmds; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 92 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 93 | static void add_cmdname(struct cmdnames *cmds, const char *name, int len) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 94 | { |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 95 | struct cmdname *ent = xmalloc(sizeof(*ent) + len); |
| 96 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 97 | ent->len = len; |
| 98 | memcpy(ent->name, name, len); |
| 99 | ent->name[len] = 0; |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 100 | |
| 101 | ALLOC_GROW(cmds->names, cmds->cnt + 1, cmds->alloc); |
| 102 | cmds->names[cmds->cnt++] = ent; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static int cmdname_compare(const void *a_, const void *b_) |
| 106 | { |
| 107 | struct cmdname *a = *(struct cmdname **)a_; |
| 108 | struct cmdname *b = *(struct cmdname **)b_; |
| 109 | return strcmp(a->name, b->name); |
| 110 | } |
| 111 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 112 | static void uniq(struct cmdnames *cmds) |
| 113 | { |
| 114 | int i, j; |
| 115 | |
| 116 | if (!cmds->cnt) |
| 117 | return; |
| 118 | |
| 119 | for (i = j = 1; i < cmds->cnt; i++) |
| 120 | if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) |
| 121 | cmds->names[j++] = cmds->names[i]; |
| 122 | |
| 123 | cmds->cnt = j; |
| 124 | } |
| 125 | |
Junio C Hamano | f3fa183 | 2007-11-08 15:35:32 -0800 | [diff] [blame] | 126 | static void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes) |
| 127 | { |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 128 | int ci, cj, ei; |
| 129 | int cmp; |
| 130 | |
| 131 | ci = cj = ei = 0; |
| 132 | while (ci < cmds->cnt && ei < excludes->cnt) { |
| 133 | cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name); |
| 134 | if (cmp < 0) |
| 135 | cmds->names[cj++] = cmds->names[ci++]; |
| 136 | else if (cmp == 0) |
| 137 | ci++, ei++; |
| 138 | else if (cmp > 0) |
| 139 | ei++; |
| 140 | } |
| 141 | |
| 142 | while (ci < cmds->cnt) |
| 143 | cmds->names[cj++] = cmds->names[ci++]; |
| 144 | |
| 145 | cmds->cnt = cj; |
| 146 | } |
| 147 | |
| 148 | static void pretty_print_string_list(struct cmdnames *cmds, int longest) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 149 | { |
| 150 | int cols = 1, rows; |
| 151 | int space = longest + 1; /* min 1 SP between words */ |
| 152 | int max_cols = term_columns() - 1; /* don't print *on* the edge */ |
| 153 | int i, j; |
| 154 | |
| 155 | if (space < max_cols) |
| 156 | cols = max_cols / space; |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 157 | rows = (cmds->cnt + cols - 1) / cols; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 158 | |
| 159 | for (i = 0; i < rows; i++) { |
| 160 | printf(" "); |
| 161 | |
| 162 | for (j = 0; j < cols; j++) { |
| 163 | int n = j * rows + i; |
| 164 | int size = space; |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 165 | if (n >= cmds->cnt) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 166 | break; |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 167 | if (j == cols-1 || n + rows >= cmds->cnt) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 168 | size = 1; |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 169 | printf("%-*s", size, cmds->names[n]->name); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 170 | } |
| 171 | putchar('\n'); |
| 172 | } |
| 173 | } |
| 174 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 175 | static unsigned int list_commands_in_dir(struct cmdnames *cmds, |
| 176 | const char *path) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 177 | { |
| 178 | unsigned int longest = 0; |
Scott R Parish | edb6ddc | 2007-10-27 01:36:50 -0700 | [diff] [blame] | 179 | const char *prefix = "git-"; |
| 180 | int prefix_len = strlen(prefix); |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 181 | DIR *dir = opendir(path); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 182 | struct dirent *de; |
| 183 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 184 | if (!dir || chdir(path)) |
| 185 | return 0; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 186 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 187 | while ((de = readdir(dir)) != NULL) { |
| 188 | struct stat st; |
| 189 | int entlen; |
| 190 | |
Scott R Parish | edb6ddc | 2007-10-27 01:36:50 -0700 | [diff] [blame] | 191 | if (prefixcmp(de->d_name, prefix)) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 192 | continue; |
Scott R Parish | 0966003 | 2007-10-27 01:36:52 -0700 | [diff] [blame] | 193 | |
| 194 | if (stat(de->d_name, &st) || /* stat, not lstat */ |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 195 | !S_ISREG(st.st_mode) || |
| 196 | !(st.st_mode & S_IXUSR)) |
| 197 | continue; |
| 198 | |
Scott R Parish | edb6ddc | 2007-10-27 01:36:50 -0700 | [diff] [blame] | 199 | entlen = strlen(de->d_name) - prefix_len; |
Rene Scharfe | 5bb1cda | 2006-08-11 14:01:45 +0200 | [diff] [blame] | 200 | if (has_extension(de->d_name, ".exe")) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 201 | entlen -= 4; |
| 202 | |
| 203 | if (longest < entlen) |
| 204 | longest = entlen; |
| 205 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 206 | add_cmdname(cmds, de->d_name + prefix_len, entlen); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 207 | } |
| 208 | closedir(dir); |
| 209 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 210 | return longest; |
| 211 | } |
| 212 | |
Jeff King | 2156435 | 2008-02-24 17:17:37 -0500 | [diff] [blame] | 213 | static unsigned int load_command_list(void) |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 214 | { |
| 215 | unsigned int longest = 0; |
| 216 | unsigned int len; |
| 217 | const char *env_path = getenv("PATH"); |
| 218 | char *paths, *path, *colon; |
| 219 | const char *exec_path = git_exec_path(); |
| 220 | |
| 221 | if (exec_path) |
| 222 | longest = list_commands_in_dir(&main_cmds, exec_path); |
| 223 | |
| 224 | if (!env_path) { |
| 225 | fprintf(stderr, "PATH not set\n"); |
| 226 | exit(1); |
| 227 | } |
| 228 | |
| 229 | path = paths = xstrdup(env_path); |
| 230 | while (1) { |
| 231 | if ((colon = strchr(path, ':'))) |
| 232 | *colon = 0; |
| 233 | |
| 234 | len = list_commands_in_dir(&other_cmds, path); |
| 235 | if (len > longest) |
| 236 | longest = len; |
| 237 | |
| 238 | if (!colon) |
| 239 | break; |
| 240 | path = colon + 1; |
| 241 | } |
| 242 | free(paths); |
| 243 | |
| 244 | qsort(main_cmds.names, main_cmds.cnt, |
| 245 | sizeof(*main_cmds.names), cmdname_compare); |
| 246 | uniq(&main_cmds); |
| 247 | |
| 248 | qsort(other_cmds.names, other_cmds.cnt, |
| 249 | sizeof(*other_cmds.names), cmdname_compare); |
| 250 | uniq(&other_cmds); |
| 251 | exclude_cmds(&other_cmds, &main_cmds); |
| 252 | |
Jeff King | 2156435 | 2008-02-24 17:17:37 -0500 | [diff] [blame] | 253 | return longest; |
| 254 | } |
| 255 | |
| 256 | static void list_commands(void) |
| 257 | { |
| 258 | unsigned int longest = load_command_list(); |
| 259 | const char *exec_path = git_exec_path(); |
| 260 | |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 261 | if (main_cmds.cnt) { |
| 262 | printf("available git commands in '%s'\n", exec_path); |
| 263 | printf("----------------------------"); |
| 264 | mput_char('-', strlen(exec_path)); |
| 265 | putchar('\n'); |
| 266 | pretty_print_string_list(&main_cmds, longest); |
| 267 | putchar('\n'); |
| 268 | } |
| 269 | |
| 270 | if (other_cmds.cnt) { |
| 271 | printf("git commands available from elsewhere on your $PATH\n"); |
| 272 | printf("---------------------------------------------------\n"); |
| 273 | pretty_print_string_list(&other_cmds, longest); |
| 274 | putchar('\n'); |
| 275 | } |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Scott R Parish | 3d7e2d8 | 2007-10-27 01:36:49 -0700 | [diff] [blame] | 278 | void list_common_cmds_help(void) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 279 | { |
| 280 | int i, longest = 0; |
| 281 | |
| 282 | for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { |
| 283 | if (longest < strlen(common_cmds[i].name)) |
| 284 | longest = strlen(common_cmds[i].name); |
| 285 | } |
| 286 | |
| 287 | puts("The most commonly used git commands are:"); |
| 288 | for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { |
Ren,bi(B Scharfe | 4f75b11 | 2007-02-11 14:29:58 +0100 | [diff] [blame] | 289 | printf(" %s ", common_cmds[i].name); |
| 290 | mput_char(' ', longest - strlen(common_cmds[i].name)); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 291 | puts(common_cmds[i].help); |
| 292 | } |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Jeff King | 2156435 | 2008-02-24 17:17:37 -0500 | [diff] [blame] | 295 | static int is_in_cmdlist(struct cmdnames *c, const char *s) |
| 296 | { |
| 297 | int i; |
| 298 | for (i = 0; i < c->cnt; i++) |
| 299 | if (!strcmp(s, c->names[i]->name)) |
| 300 | return 1; |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int is_git_command(const char *s) |
| 305 | { |
| 306 | load_command_list(); |
| 307 | return is_in_cmdlist(&main_cmds, s) || |
| 308 | is_in_cmdlist(&other_cmds, s); |
| 309 | } |
| 310 | |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 311 | static const char *cmd_to_page(const char *git_cmd) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 312 | { |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 313 | if (!git_cmd) |
| 314 | return "git"; |
| 315 | else if (!prefixcmp(git_cmd, "git")) |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 316 | return git_cmd; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 317 | else { |
| 318 | int page_len = strlen(git_cmd) + 4; |
Jonas Fonseca | 2d7320d | 2006-09-01 00:32:39 +0200 | [diff] [blame] | 319 | char *p = xmalloc(page_len + 1); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 320 | strcpy(p, "git-"); |
| 321 | strcpy(p + 4, git_cmd); |
| 322 | p[page_len] = 0; |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 323 | return p; |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 324 | } |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 325 | } |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 326 | |
Sergei Organov | 8e566f2 | 2007-12-06 21:33:01 +0300 | [diff] [blame] | 327 | static void setup_man_path(void) |
| 328 | { |
| 329 | struct strbuf new_path; |
| 330 | const char *old_path = getenv("MANPATH"); |
| 331 | |
| 332 | strbuf_init(&new_path, 0); |
| 333 | |
| 334 | /* We should always put ':' after our path. If there is no |
| 335 | * old_path, the ':' at the end will let 'man' to try |
| 336 | * system-wide paths after ours to find the manual page. If |
| 337 | * there is old_path, we need ':' as delimiter. */ |
| 338 | strbuf_addstr(&new_path, GIT_MAN_PATH); |
| 339 | strbuf_addch(&new_path, ':'); |
| 340 | if (old_path) |
| 341 | strbuf_addstr(&new_path, old_path); |
| 342 | |
| 343 | setenv("MANPATH", new_path.buf, 1); |
| 344 | |
| 345 | strbuf_release(&new_path); |
| 346 | } |
| 347 | |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 348 | static void show_man_page(const char *git_cmd) |
| 349 | { |
| 350 | const char *page = cmd_to_page(git_cmd); |
Sergei Organov | 8e566f2 | 2007-12-06 21:33:01 +0300 | [diff] [blame] | 351 | setup_man_path(); |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 352 | execlp("man", "man", page, NULL); |
| 353 | } |
| 354 | |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 355 | static void show_info_page(const char *git_cmd) |
| 356 | { |
| 357 | const char *page = cmd_to_page(git_cmd); |
Junio C Hamano | a149a1a | 2007-12-10 01:35:29 -0800 | [diff] [blame] | 358 | setenv("INFOPATH", GIT_INFO_PATH, 1); |
Junio C Hamano | 78d39f9 | 2007-12-10 01:19:31 -0800 | [diff] [blame] | 359 | execlp("info", "info", "gitman", page, NULL); |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Christian Couder | 482cce8 | 2008-02-02 07:32:33 +0100 | [diff] [blame] | 362 | static void get_html_page_path(struct strbuf *page_path, const char *page) |
| 363 | { |
| 364 | struct stat st; |
| 365 | |
| 366 | /* Check that we have a git documentation directory. */ |
| 367 | if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode)) |
| 368 | die("'%s': not a documentation directory.", GIT_HTML_PATH); |
| 369 | |
| 370 | strbuf_init(page_path, 0); |
| 371 | strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page); |
| 372 | } |
| 373 | |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 374 | static void show_html_page(const char *git_cmd) |
| 375 | { |
| 376 | const char *page = cmd_to_page(git_cmd); |
Christian Couder | 482cce8 | 2008-02-02 07:32:33 +0100 | [diff] [blame] | 377 | struct strbuf page_path; /* it leaks but we exec bellow */ |
| 378 | |
| 379 | get_html_page_path(&page_path, page); |
| 380 | |
Christian Couder | 5884f1f | 2008-02-02 07:32:53 +0100 | [diff] [blame] | 381 | execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL); |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 384 | void help_unknown_cmd(const char *cmd) |
| 385 | { |
Junio C Hamano | a238917 | 2007-10-26 23:26:41 -0700 | [diff] [blame] | 386 | fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd); |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 387 | exit(1); |
| 388 | } |
| 389 | |
Linus Torvalds | a633fca | 2006-07-28 22:44:25 -0700 | [diff] [blame] | 390 | int cmd_version(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 391 | { |
| 392 | printf("git version %s\n", git_version_string); |
| 393 | return 0; |
| 394 | } |
| 395 | |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 396 | int cmd_help(int argc, const char **argv, const char *prefix) |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 397 | { |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 398 | int nongit; |
Jeff King | 2156435 | 2008-02-24 17:17:37 -0500 | [diff] [blame] | 399 | const char *alias; |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 400 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 401 | setup_git_directory_gently(&nongit); |
| 402 | git_config(git_help_config); |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 403 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 404 | argc = parse_options(argc, argv, builtin_help_options, |
| 405 | builtin_help_usage, 0); |
| 406 | |
| 407 | if (show_all) { |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 408 | printf("usage: %s\n\n", git_usage_string); |
Scott R Parish | 1eb0569 | 2007-10-28 20:30:52 -0700 | [diff] [blame] | 409 | list_commands(); |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 410 | return 0; |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 411 | } |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 412 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 413 | if (!argv[0]) { |
| 414 | printf("usage: %s\n\n", git_usage_string); |
| 415 | list_common_cmds_help(); |
| 416 | return 0; |
Christian Couder | 5d6491c | 2007-12-02 06:07:55 +0100 | [diff] [blame] | 417 | } |
Christian Couder | df55c9c | 2007-12-02 06:07:40 +0100 | [diff] [blame] | 418 | |
Jeff King | 2156435 | 2008-02-24 17:17:37 -0500 | [diff] [blame] | 419 | alias = alias_lookup(argv[0]); |
| 420 | if (alias && !is_git_command(argv[0])) { |
| 421 | printf("`git %s' is aliased to `%s'\n", argv[0], alias); |
| 422 | return 0; |
| 423 | } |
| 424 | |
Jeff King | 41eb33b | 2008-02-24 17:16:55 -0500 | [diff] [blame] | 425 | switch (help_format) { |
| 426 | case HELP_FORMAT_MAN: |
| 427 | show_man_page(argv[0]); |
| 428 | break; |
| 429 | case HELP_FORMAT_INFO: |
| 430 | show_info_page(argv[0]); |
| 431 | break; |
| 432 | case HELP_FORMAT_WEB: |
| 433 | show_html_page(argv[0]); |
| 434 | break; |
Christian Couder | 70087cd | 2007-12-15 05:57:28 +0100 | [diff] [blame] | 435 | } |
Ramsay Allan Jones | 822a7d5 | 2006-07-30 22:42:25 +0100 | [diff] [blame] | 436 | |
Linus Torvalds | 70827b1 | 2006-04-21 10:27:34 -0700 | [diff] [blame] | 437 | return 0; |
| 438 | } |