aboutsummaryrefslogtreecommitdiffstats
path: root/builtin-help.c
diff options
context:
space:
mode:
authorSasha Levin <levinsasha928@gmail.com>2011-07-09 09:57:29 +0300
committerWill Deacon <will.deacon@arm.com>2015-06-01 16:39:46 +0100
commit2a24f96d648d5a281ae506ca6125404d1edbe7f5 (patch)
treec2e9719877ebf6502dd640bad30c175e50e7563c /builtin-help.c
parentfae27ee3cac49b6056c816d0e931d8e6a72a3579 (diff)
downloadkvmtool-2a24f96d648d5a281ae506ca6125404d1edbe7f5.tar.gz
kvm tools: Rename command source files
Rename kvm-[command] into builtin-[command] to prevent clashes with non-command files such as kvm-cpu.h Suggested-by: Pekka Enberg <penberg@kernel.org> Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'builtin-help.c')
-rw-r--r--builtin-help.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/builtin-help.c b/builtin-help.c
new file mode 100644
index 00000000..e89cd5cf
--- /dev/null
+++ b/builtin-help.c
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <string.h>
+
+/* user defined headers */
+#include <common-cmds.h>
+
+#include <kvm/util.h>
+#include <kvm/kvm-cmd.h>
+#include <kvm/builtin-help.h>
+
+
+const char kvm_usage_string[] =
+ "kvm [--version] [--help] COMMAND [ARGS]";
+
+const char kvm_more_info_string[] =
+ "See 'kvm help COMMAND' for more information on a specific command.";
+
+
+static void list_common_cmds_help(void)
+{
+ unsigned int i, longest = 0;
+
+ for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
+ if (longest < strlen(common_cmds[i].name))
+ longest = strlen(common_cmds[i].name);
+ }
+
+ puts(" The most commonly used kvm commands are:");
+ for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
+ printf(" %-*s ", longest, common_cmds[i].name);
+ puts(common_cmds[i].help);
+ }
+}
+
+static void kvm_help(void)
+{
+ printf("\n usage: %s\n\n", kvm_usage_string);
+ list_common_cmds_help();
+ printf("\n %s\n\n", kvm_more_info_string);
+}
+
+
+static void help_cmd(const char *cmd)
+{
+ struct cmd_struct *p;
+ p = kvm_get_command(kvm_commands, cmd);
+ if (!p)
+ kvm_help();
+ else if (p->help)
+ p->help();
+}
+
+int kvm_cmd_help(int argc, const char **argv, const char *prefix)
+{
+ if (!argv || !*argv) {
+ kvm_help();
+ return 0;
+ }
+ help_cmd(argv[0]);
+ return 0;
+}