diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-06-01 15:06:37 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-06-01 15:06:37 +0900 |
commit | 2289880f784326dc955f213072164539dcaf445e (patch) | |
tree | 3e6d5465c144c76ffacde79aa33f9252b1e53a6e /git.c | |
parent | 2161ed80980dc774521b963d8b4b18f746124283 (diff) | |
parent | 6532f3740b1c228c0a2a03a4126f4f7e4f2d73e7 (diff) | |
download | git-2289880f784326dc955f213072164539dcaf445e.tar.gz |
Merge branch 'nd/command-list'
The list of commands with their various attributes were spread
across a few places in the build procedure, but it now is getting a
bit more consolidated to allow more automation.
* nd/command-list:
completion: allow to customize the completable command list
completion: add and use --list-cmds=alias
completion: add and use --list-cmds=nohelpers
Move declaration for alias.c to alias.h
completion: reduce completable command list
completion: let git provide the completable command list
command-list.txt: documentation and guide line
help: use command-list.txt for the source of guides
help: add "-a --verbose" to list all commands with synopsis
git: support --list-cmds=list-<category>
completion: implement and use --list-cmds=main,others
git --list-cmds: collect command list in a string_list
git.c: convert --list-* to --list-cmds=*
Remove common-cmds.h
help: use command-list.h for common command list
generate-cmds.sh: export all commands to command-list.h
generate-cmds.sh: factor out synopsis extract code
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 85 |
1 files changed, 76 insertions, 9 deletions
@@ -3,6 +3,7 @@ #include "exec-cmd.h" #include "help.h" #include "run-command.h" +#include "alias.h" #define RUN_SETUP (1<<0) #define RUN_SETUP_GENTLY (1<<1) @@ -36,7 +37,66 @@ const char git_more_info_string[] = static int use_pager = -1; -static void list_builtins(unsigned int exclude_option, char sep); +static void list_builtins(struct string_list *list, unsigned int exclude_option); + +static void exclude_helpers_from_list(struct string_list *list) +{ + int i = 0; + + while (i < list->nr) { + if (strstr(list->items[i].string, "--")) + unsorted_string_list_delete_item(list, i, 0); + else + i++; + } +} + +static int match_token(const char *spec, int len, const char *token) +{ + int token_len = strlen(token); + + return len == token_len && !strncmp(spec, token, token_len); +} + +static int list_cmds(const char *spec) +{ + struct string_list list = STRING_LIST_INIT_DUP; + int i; + + while (*spec) { + const char *sep = strchrnul(spec, ','); + int len = sep - spec; + + if (match_token(spec, len, "builtins")) + list_builtins(&list, 0); + else if (match_token(spec, len, "main")) + list_all_main_cmds(&list); + else if (match_token(spec, len, "others")) + list_all_other_cmds(&list); + else if (match_token(spec, len, "nohelpers")) + exclude_helpers_from_list(&list); + else if (match_token(spec, len, "alias")) + list_aliases(&list); + else if (match_token(spec, len, "config")) + list_cmds_by_config(&list); + else if (len > 5 && !strncmp(spec, "list-", 5)) { + struct strbuf sb = STRBUF_INIT; + + strbuf_add(&sb, spec + 5, len - 5); + list_cmds_by_category(&list, sb.buf); + strbuf_release(&sb); + } + else + die(_("unsupported command listing type '%s'"), spec); + spec += len; + if (*spec == ',') + spec++; + } + for (i = 0; i < list.nr; i++) + puts(list.items[i].string); + string_list_clear(&list, 0); + return 0; +} static void commit_pager_choice(void) { switch (use_pager) { @@ -223,12 +283,19 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) } (*argv)++; (*argc)--; - } else if (!strcmp(cmd, "--list-builtins")) { - list_builtins(0, '\n'); - exit(0); - } else if (!strcmp(cmd, "--list-parseopt-builtins")) { - list_builtins(NO_PARSEOPT, ' '); - exit(0); + } else if (skip_prefix(cmd, "--list-cmds=", &cmd)) { + if (!strcmp(cmd, "parseopt")) { + struct string_list list = STRING_LIST_INIT_DUP; + int i; + + list_builtins(&list, NO_PARSEOPT); + for (i = 0; i < list.nr; i++) + printf("%s ", list.items[i].string); + string_list_clear(&list, 0); + exit(0); + } else { + exit(list_cmds(cmd)); + } } else { fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); @@ -511,14 +578,14 @@ int is_builtin(const char *s) return !!get_builtin(s); } -static void list_builtins(unsigned int exclude_option, char sep) +static void list_builtins(struct string_list *out, unsigned int exclude_option) { int i; for (i = 0; i < ARRAY_SIZE(commands); i++) { if (exclude_option && (commands[i].option & exclude_option)) continue; - printf("%s%c", commands[i].cmd, sep); + string_list_append(out, commands[i].cmd); } } |