| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 1 | #ifndef HELP_H |
| 2 | #define HELP_H |
| 3 | |
| Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 13:55:24 | [diff] [blame] | 4 | #include "string-list.h" |
| 5 | #include "strbuf.h" |
| Nguyễn Thái Ngọc Duy | 6bb2dc0 | 2018-05-20 18:39:59 | [diff] [blame] | 6 | |
| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 7 | struct cmdnames { |
| 8 | int alloc; |
| 9 | int cnt; |
| 10 | struct cmdname { |
| Johannes Schindelin | 8af84da | 2008-08-31 13:50:23 | [diff] [blame] | 11 | size_t len; /* also used for similarity index in help.c */ |
| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 12 | char name[FLEX_ARRAY]; |
| 13 | } **names; |
| 14 | }; |
| 15 | |
| Miklos Vajna | 3d78d1f | 2008-08-02 08:08:38 | [diff] [blame] | 16 | static inline void mput_char(char c, unsigned int num) |
| 17 | { |
| Johannes Schindelin | 5acea87 | 2018-12-11 14:58:10 | [diff] [blame] | 18 | while (num--) |
| Miklos Vajna | 3d78d1f | 2008-08-02 08:08:38 | [diff] [blame] | 19 | putchar(c); |
| 20 | } |
| 21 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 22 | void list_common_cmds_help(void); |
| 23 | void list_all_cmds_help(void); |
| Philippe Blain | 0371a76 | 2020-08-05 01:19:05 | [diff] [blame] | 24 | void list_guides_help(void); |
| Nguyễn Thái Ngọc Duy | 63eae83 | 2018-05-20 18:40:01 | [diff] [blame] | 25 | |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 26 | void list_all_main_cmds(struct string_list *list); |
| 27 | void list_all_other_cmds(struct string_list *list); |
| 28 | void list_cmds_by_category(struct string_list *list, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 29 | const char *category); |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 30 | void list_cmds_by_config(struct string_list *list); |
| 31 | const char *help_unknown_cmd(const char *cmd); |
| 32 | void load_command_list(const char *prefix, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 33 | struct cmdnames *main_cmds, |
| 34 | struct cmdnames *other_cmds); |
| Johannes Schindelin | 722fc37 | 2020-10-07 21:56:51 | [diff] [blame] | 35 | void load_builtin_commands(const char *prefix, struct cmdnames *cmds); |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 36 | void add_cmdname(struct cmdnames *cmds, const char *name, int len); |
| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 37 | /* Here we require that excludes is a sorted list. */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 38 | void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes); |
| 39 | int is_in_cmdlist(struct cmdnames *cmds, const char *name); |
| 40 | void list_commands(unsigned int colopts, struct cmdnames *main_cmds, struct cmdnames *other_cmds); |
| Emily Shaffer | 617d571 | 2020-04-16 21:18:05 | [diff] [blame] | 41 | void get_version_info(struct strbuf *buf, int show_build_options); |
| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 42 | |
| Vikrant Varma | e561810 | 2013-05-04 00:04:19 | [diff] [blame] | 43 | /* |
| 44 | * call this to die(), when it is suspected that the user mistyped a |
| 45 | * ref to the command, to give suggested "correct" refs. |
| 46 | */ |
| René Scharfe | 80e3658 | 2019-08-29 19:13:16 | [diff] [blame] | 47 | NORETURN void help_unknown_ref(const char *ref, const char *cmd, const char *error); |
| Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 13:55:24 | [diff] [blame] | 48 | |
| 49 | static inline void list_config_item(struct string_list *list, |
| 50 | const char *prefix, |
| 51 | const char *str) |
| 52 | { |
| 53 | string_list_append_nodup(list, xstrfmt("%s.%s", prefix, str)); |
| 54 | } |
| 55 | |
| 56 | #define define_list_config_array(array) \ |
| 57 | void list_config_##array(struct string_list *list, const char *prefix) \ |
| 58 | { \ |
| 59 | int i; \ |
| 60 | for (i = 0; i < ARRAY_SIZE(array); i++) \ |
| 61 | if (array[i]) \ |
| 62 | list_config_item(list, prefix, array[i]); \ |
| 63 | } \ |
| 64 | struct string_list |
| 65 | |
| 66 | #define define_list_config_array_extra(array, values) \ |
| 67 | void list_config_##array(struct string_list *list, const char *prefix) \ |
| 68 | { \ |
| 69 | int i; \ |
| 70 | static const char *extra[] = values; \ |
| 71 | for (i = 0; i < ARRAY_SIZE(extra); i++) \ |
| 72 | list_config_item(list, prefix, extra[i]); \ |
| 73 | for (i = 0; i < ARRAY_SIZE(array); i++) \ |
| 74 | if (array[i]) \ |
| 75 | list_config_item(list, prefix, array[i]); \ |
| 76 | } \ |
| 77 | struct string_list |
| 78 | |
| 79 | /* These are actually scattered over many C files */ |
| 80 | void list_config_advices(struct string_list *list, const char *prefix); |
| 81 | void list_config_color_branch_slots(struct string_list *list, const char *prefix); |
| 82 | void list_config_color_decorate_slots(struct string_list *list, const char *prefix); |
| 83 | void list_config_color_diff_slots(struct string_list *list, const char *prefix); |
| 84 | void list_config_color_grep_slots(struct string_list *list, const char *prefix); |
| 85 | void list_config_color_interactive_slots(struct string_list *list, const char *prefix); |
| 86 | void list_config_color_status_slots(struct string_list *list, const char *prefix); |
| Han-Wen Nienhuys | bf1a11f | 2018-08-07 12:51:08 | [diff] [blame] | 87 | void list_config_color_sideband_slots(struct string_list *list, const char *prefix); |
| Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 13:55:24 | [diff] [blame] | 88 | void list_config_fsck_msg_ids(struct string_list *list, const char *prefix); |
| 89 | |
| Miklos Vajna | 940208a | 2008-07-29 23:16:58 | [diff] [blame] | 90 | #endif /* HELP_H */ |