]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
2bd0ea18 NS |
5 | */ |
6 | ||
6b803e5a | 7 | #include "libxfs.h" |
2bd0ea18 NS |
8 | #include "command.h" |
9 | #include "help.h" | |
10 | #include "output.h" | |
11 | ||
12 | static void help_all(void); | |
13 | static void help_onecmd(const char *cmd, const cmdinfo_t *ct); | |
14 | static int help_f(int argc, char **argv); | |
15 | static void help_oneline(const char *cmd, const cmdinfo_t *ct); | |
16 | ||
17 | static const cmdinfo_t help_cmd = | |
9ee7055c AM |
18 | { "help", "?", help_f, 0, 1, 0, N_("[command]"), |
19 | N_("help for one or all commands"), NULL }; | |
2bd0ea18 NS |
20 | |
21 | static void | |
22 | help_all(void) | |
23 | { | |
24 | const cmdinfo_t *ct; | |
25 | ||
26 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) | |
27 | help_oneline(ct->name, ct); | |
9ee7055c | 28 | dbprintf(_("\nUse 'help commandname' for extended help.\n")); |
2bd0ea18 NS |
29 | } |
30 | ||
31 | static int | |
32 | help_f( | |
33 | int argc, | |
34 | char **argv) | |
35 | { | |
36 | const cmdinfo_t *ct; | |
37 | ||
38 | if (argc == 1) { | |
39 | help_all(); | |
40 | return 0; | |
41 | } | |
42 | ct = find_command(argv[1]); | |
43 | if (ct == NULL) { | |
9ee7055c | 44 | dbprintf(_("command %s not found\n"), argv[1]); |
2bd0ea18 NS |
45 | return 0; |
46 | } | |
47 | help_onecmd(argv[1], ct); | |
48 | return 0; | |
49 | } | |
50 | ||
51 | void | |
52 | help_init(void) | |
53 | { | |
54 | add_command(&help_cmd); | |
55 | } | |
56 | ||
57 | static void | |
58 | help_onecmd( | |
59 | const char *cmd, | |
60 | const cmdinfo_t *ct) | |
61 | { | |
62 | help_oneline(cmd, ct); | |
63 | if (ct->help) | |
64 | ct->help(); | |
65 | } | |
66 | ||
67 | static void | |
68 | help_oneline( | |
69 | const char *cmd, | |
70 | const cmdinfo_t *ct) | |
71 | { | |
72 | if (cmd) | |
73 | dbprintf("%s ", cmd); | |
74 | else { | |
75 | dbprintf("%s ", ct->name); | |
76 | if (ct->altname) | |
9ee7055c | 77 | dbprintf(_("(or %s) "), ct->altname); |
2bd0ea18 NS |
78 | } |
79 | if (ct->args) | |
80 | dbprintf("%s ", ct->args); | |
81 | dbprintf("-- %s\n", ct->oneline); | |
82 | } |