-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplinter_cli_cmd_help.c
More file actions
58 lines (50 loc) · 1.63 KB
/
splinter_cli_cmd_help.c
File metadata and controls
58 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright 2025 Tim Post
* License: Apache 2 (MIT available upon request to timthepost@protonmail.com)
*
* @file splinter_cli_cmd_help.c
* @brief Implements the CLI 'help' command.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "splinter_cli.h"
static const char *modname = "help";
void help_cmd_help(unsigned int level) {
printf("%s provides help for this CLI.\nUsage: help [ext] <module_name>\n",
modname);
printf("Example: '%s ext help' shows the extended help display for this command, 'help'.\n",
modname);
printf(" 'help' lists available commands and how to show additional help.\n");
if (level) {
puts("\nNot all commands have extended help displays.");
puts("Please report problems with help coverage on Github:");
puts("https://github.com/timthepost/libsplinter");
}
}
int cmd_help(int argc, char *argv[]) {
int idx;
unsigned int ext_mode = 0;
if (argc == 1 ) {
cli_show_modules();
puts("\nFor help on a particular module, type 'help <module>'");
puts("For extended help on a particular module, type 'help ext <module>'");
return 0;
}
if (! strncmp(argv[1], "ext", 3) && argc >= 3) {
ext_mode = 1;
idx = cli_find_module(argv[2]);
} else {
idx = cli_find_module(argv[1]);
}
// 0 is a valid index (the 'help' command by default)
if (idx >= 0) {
cli_show_module_help(idx, ext_mode);
return 0;
} else {
fprintf(stderr, "Could not find help for '%s'\n", argv[1]);
errno = EINVAL;
return 1;
}
}