]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxcmd/help.c
xfsprogs: handle symlinks etc in fs_table_initialise_mounts()
[thirdparty/xfsprogs-dev.git] / libxcmd / help.c
CommitLineData
e246ba5f 1/*
da23017d
NS
2 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
e246ba5f 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
e246ba5f
NS
17 */
18
2a1888c5 19#include <xfs/xfs.h>
3d93ccb7 20#include <xfs/command.h>
e246ba5f
NS
21
22static cmdinfo_t help_cmd;
23static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
24static void help_oneline(const char *cmd, const cmdinfo_t *ct);
25
26static void
27help_all(void)
28{
29 const cmdinfo_t *ct;
30
31 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++)
32 help_oneline(ct->name, ct);
33 printf(_("\nUse 'help commandname' for extended help.\n"));
34}
35
36static int
37help_f(
38 int argc,
39 char **argv)
40{
41 const cmdinfo_t *ct;
42
43 if (argc == 1) {
44 help_all();
45 return 0;
46 }
47 ct = find_command(argv[1]);
48 if (ct == NULL) {
49 printf(_("command %s not found\n"), argv[1]);
50 return 0;
51 }
52 help_onecmd(argv[1], ct);
53 return 0;
54}
55
56static void
57help_onecmd(
58 const char *cmd,
59 const cmdinfo_t *ct)
60{
61 help_oneline(cmd, ct);
62 if (ct->help)
63 ct->help();
64}
65
66static void
67help_oneline(
68 const char *cmd,
69 const cmdinfo_t *ct)
70{
71 if (cmd)
72 printf("%s ", cmd);
73 else {
74 printf("%s ", ct->name);
75 if (ct->altname)
76 printf("(or %s) ", ct->altname);
77 }
78 if (ct->args)
79 printf("%s ", ct->args);
80 printf("-- %s\n", ct->oneline);
81}
82
83void
84help_init(void)
85{
ad765595
AM
86 help_cmd.name = "help";
87 help_cmd.altname = "?";
e246ba5f
NS
88 help_cmd.cfunc = help_f;
89 help_cmd.argmin = 0;
90 help_cmd.argmax = 1;
802d66e3 91 help_cmd.flags = CMD_FLAG_GLOBAL;
e246ba5f
NS
92 help_cmd.args = _("[command]");
93 help_cmd.oneline = _("help for one or all commands");
94
95 add_command(&help_cmd);
96}