]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxcmd/help.c
xfs_io: support passing the FORCE_REBUILD flag to online repair
[thirdparty/xfsprogs-dev.git] / libxcmd / help.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "platform_defs.h"
8 #include "command.h"
9 #include "../quota/init.h"
10
11 static cmdinfo_t help_cmd;
12 static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
13 static void help_oneline(const char *cmd, const cmdinfo_t *ct);
14
15 static void
16 help_all(void)
17 {
18 const cmdinfo_t *ct;
19
20 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++)
21 help_oneline(ct->name, ct);
22 printf(_("\nUse 'help commandname' for extended help.\n"));
23 }
24
25 static int
26 help_f(
27 int argc,
28 char **argv)
29 {
30 const cmdinfo_t *ct;
31
32 if (argc == 1) {
33 help_all();
34 return 0;
35 }
36 ct = find_command(argv[1]);
37 if (ct == NULL) {
38 printf(_("command %s not found\n"), argv[1]);
39 return 0;
40 }
41 help_onecmd(argv[1], ct);
42 return 0;
43 }
44
45 static void
46 help_onecmd(
47 const char *cmd,
48 const cmdinfo_t *ct)
49 {
50 help_oneline(cmd, ct);
51 if (ct->help)
52 ct->help();
53 }
54
55 static void
56 help_oneline(
57 const char *cmd,
58 const cmdinfo_t *ct)
59 {
60 if (cmd)
61 printf("%s ", cmd);
62 else {
63 printf("%s ", ct->name);
64 if (ct->altname)
65 printf("(or %s) ", ct->altname);
66 }
67 if (ct->args)
68 printf("%s ", ct->args);
69 printf("-- %s\n", ct->oneline);
70 }
71
72 void
73 help_init(void)
74 {
75 help_cmd.name = "help";
76 help_cmd.altname = "?";
77 help_cmd.cfunc = help_f;
78 help_cmd.argmin = 0;
79 help_cmd.argmax = 1;
80 help_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_LIBRARY;
81 help_cmd.args = _("[command]");
82 help_cmd.oneline = _("help for one or all commands");
83
84 add_command(&help_cmd);
85 }