]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxcmd/help.c
xfs_quota: certain commands must always be available
[thirdparty/xfsprogs-dev.git] / libxcmd / help.c
1 /*
2 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "platform_defs.h"
20 #include "command.h"
21 #include "../quota/init.h"
22
23 static cmdinfo_t help_cmd;
24 static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
25 static void help_oneline(const char *cmd, const cmdinfo_t *ct);
26
27 static void
28 help_all(void)
29 {
30 const cmdinfo_t *ct;
31
32 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++)
33 help_oneline(ct->name, ct);
34 printf(_("\nUse 'help commandname' for extended help.\n"));
35 }
36
37 static int
38 help_f(
39 int argc,
40 char **argv)
41 {
42 const cmdinfo_t *ct;
43
44 if (argc == 1) {
45 help_all();
46 return 0;
47 }
48 ct = find_command(argv[1]);
49 if (ct == NULL) {
50 printf(_("command %s not found\n"), argv[1]);
51 return 0;
52 }
53 help_onecmd(argv[1], ct);
54 return 0;
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 printf("%s ", cmd);
74 else {
75 printf("%s ", ct->name);
76 if (ct->altname)
77 printf("(or %s) ", ct->altname);
78 }
79 if (ct->args)
80 printf("%s ", ct->args);
81 printf("-- %s\n", ct->oneline);
82 }
83
84 void
85 help_init(void)
86 {
87 help_cmd.name = "help";
88 help_cmd.altname = "?";
89 help_cmd.cfunc = help_f;
90 help_cmd.argmin = 0;
91 help_cmd.argmax = 1;
92 help_cmd.flags = CMD_FLAG_GLOBAL | CMD_ALL_FSTYPES;
93 help_cmd.args = _("[command]");
94 help_cmd.oneline = _("help for one or all commands");
95
96 add_command(&help_cmd);
97 }