]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/help.c
xfsprogs: Release v6.7.0
[thirdparty/xfsprogs-dev.git] / db / help.c
CommitLineData
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
12static void help_all(void);
13static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
14static int help_f(int argc, char **argv);
15static void help_oneline(const char *cmd, const cmdinfo_t *ct);
16
17static 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
21static void
22help_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
31static int
32help_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
51void
52help_init(void)
53{
54 add_command(&help_cmd);
55}
56
57static void
58help_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
67static void
68help_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}