Add linux-next specific files for 20110831
[linux-2.6/next.git] / tools / kvm / builtin-help.c
blobe70044abc26bc3ae4b1bcce137031eac1d3468b9
1 #include <stdio.h>
2 #include <string.h>
4 /* user defined headers */
5 #include <common-cmds.h>
7 #include <kvm/util.h>
8 #include <kvm/kvm-cmd.h>
9 #include <kvm/builtin-help.h>
12 const char kvm_usage_string[] =
13 "kvm COMMAND [ARGS]";
15 const char kvm_more_info_string[] =
16 "See 'kvm help COMMAND' for more information on a specific command.";
19 static void list_common_cmds_help(void)
21 unsigned int i, longest = 0;
23 for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
24 if (longest < strlen(common_cmds[i].name))
25 longest = strlen(common_cmds[i].name);
28 puts(" The most commonly used kvm commands are:");
29 for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
30 printf(" %-*s ", longest, common_cmds[i].name);
31 puts(common_cmds[i].help);
35 static void kvm_help(void)
37 printf("\n usage: %s\n\n", kvm_usage_string);
38 list_common_cmds_help();
39 printf("\n %s\n\n", kvm_more_info_string);
43 static void help_cmd(const char *cmd)
45 struct cmd_struct *p;
46 p = kvm_get_command(kvm_commands, cmd);
47 if (!p)
48 kvm_help();
49 else if (p->help)
50 p->help();
53 int kvm_cmd_help(int argc, const char **argv, const char *prefix)
55 if (!argv || !*argv) {
56 kvm_help();
57 return 0;
59 help_cmd(argv[0]);
60 return 0;