10 G(UNKNOWN, "unknown") \
14 G(GENERIC, "generic") \
18 G(CONNECTION, "connection") \
19 G(TRANSACTIONS, "transactions") \
20 G(SORTED_SET, "sorted_set")
23 * Command group types.
27 #define G(GROUP, _) COMMAND_GROUP_##GROUP,
31 } command_group_type_t
;
34 * Command group type names.
37 static char *command_group_type_names
[] = {
38 #define G(_, STR) STR,
44 * Command help struct.
51 command_group_type_t group
;
58 * Output command help to stdout.
62 output_command_help(struct command_help
*help
) {
63 printf("\n \x1b[1m%s\x1b[0m \x1b[90m%s\x1b[0m\n", help
->name
, help
->params
);
64 printf(" \x1b[33msummary:\x1b[0m %s\n", help
->summary
);
65 printf(" \x1b[33msince:\x1b[0m %s\n", help
->since
);
66 printf(" \x1b[33mgroup:\x1b[0m %s\n", command_group_type_names
[help
->group
]);
70 * Return command group type by name string.
73 static command_group_type_t
74 command_group_type_by_name(const char *name
) {
75 for (int i
= 0; i
< COMMAND_GROUP_LENGTH
; ++i
) {
76 const char *group
= command_group_type_names
[i
];
77 if (0 == strcasecmp(name
, group
)) return i
;
88 for (int i
= 0; i
< COMMAND_GROUP_LENGTH
; ++i
) {
89 if (COMMAND_GROUP_UNKNOWN
== i
) continue;
90 const char *group
= command_group_type_names
[i
];
91 printf(" \x1b[90m-\x1b[0m %s\n", group
);
96 * Output all command help, filtering by group or command name.
100 output_help(int argc
, const char **argv
) {
101 int len
= sizeof(command_help
) / sizeof(struct command_help
);
103 if (argc
&& 0 == strcasecmp("groups", argv
[0])) {
108 command_group_type_t group
= argc
109 ? command_group_type_by_name(argv
[0])
110 : COMMAND_GROUP_UNKNOWN
;
112 for (int i
= 0; i
< len
; ++i
) {
113 struct command_help help
= command_help
[i
];
114 if (argc
&& !group
&& 0 != strcasecmp(help
.name
, argv
[0])) continue;
115 if (group
&& group
!= help
.group
) continue;
116 output_command_help(&help
);