]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: implement "help xxx" command
authorAmerigo Wang <amwang@redhat.com>
Fri, 20 May 2011 07:01:24 +0000 (15:01 +0800)
committerPekka Enberg <penberg@kernel.org>
Fri, 20 May 2011 13:23:53 +0000 (16:23 +0300)
'kvm run --help' works fine but 'kvm help run' shows nothing,
this patch implements it.

Acked-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: WANG Cong <amwang@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/kvm-cmd.h
tools/kvm/include/kvm/kvm-run.h
tools/kvm/kvm-cmd.c
tools/kvm/kvm-help.c
tools/kvm/kvm-run.c
tools/kvm/main.c

index 8d5fca5a2f099ab21052e17b3dac50ca4222b7c3..0a73bce077b959eb3c829cf226c62e3588536c78 100644 (file)
@@ -4,9 +4,14 @@
 struct cmd_struct {
        const char *cmd;
        int (*fn)(int, const char **, const char *);
+       void (*help)(void);
        int option;
 };
 
+extern struct cmd_struct kvm_commands[];
+struct cmd_struct *kvm_get_command(struct cmd_struct *command,
+                const char *cmd);
+
 int handle_command(struct cmd_struct *command, int argc, const char **argv);
 
 #endif
index 13104e23f49bed87f3ac7bb1692d306d0922404e..d056ad45c7d7379e04373982417b25b7e5923d56 100644 (file)
@@ -2,5 +2,6 @@
 #define __KVM_RUN_H__
 
 int kvm_cmd_run(int argc, const char **argv, const char *prefix);
+void kvm_run_help(void);
 
 #endif
index b63e033a4cde68a3e513c8c3aa44eeec57bc8292..e545d149f556f4bc6f403bac3d03c120505130b6 100644 (file)
@@ -6,6 +6,14 @@
 
 /* user defined header files */
 #include <kvm/kvm-cmd.h>
+#include <kvm/kvm-help.h>
+#include <kvm/kvm-run.h>
+
+struct cmd_struct kvm_commands[] = {
+       { "help",  kvm_cmd_help,  NULL,         0 },
+       { "run",   kvm_cmd_run,   kvm_run_help, 0 },
+       { NULL,    NULL,          NULL,         0 },
+};
 
 /*
  * kvm_get_command: Searches the command in an array of the commands and
@@ -20,7 +28,7 @@
  * NULL: If the cmd is not matched with any of the command in the command array
  * p: Pointer to cmd_struct of the matching command
  */
-static struct cmd_struct *kvm_get_command(struct cmd_struct *command,
+struct cmd_struct *kvm_get_command(struct cmd_struct *command,
                const char *cmd)
 {
        struct cmd_struct *p = command;
index 550680760b4dc161363bfa6fdddadec1674d3661..817e4f8152d7fe13e0a1a3f5af533bd318a694ed 100644 (file)
@@ -5,6 +5,7 @@
 #include <common-cmds.h>
 
 #include <kvm/util.h>
+#include <kvm/kvm-cmd.h>
 #include <kvm/kvm-help.h>
 
 
@@ -31,13 +32,30 @@ static void list_common_cmds_help(void)
        }
 }
 
+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) {
-               printf("\n usage: %s\n\n", kvm_usage_string);
-               list_common_cmds_help();
-               printf("\n %s\n\n", kvm_more_info_string);
+               kvm_help();
                return 0;
        }
+       help_cmd(argv[0]);
        return 0;
 }
index c01517f094f956bec9396b29b05e6dc2c0681e87..f5a1790952f8312e57ab219611026bf14722c4d0 100644 (file)
@@ -395,6 +395,11 @@ static char *host_image(char *cmd_line, size_t size)
        return t;
 }
 
+void kvm_run_help(void)
+{
+       usage_with_options(run_usage, options);
+}
+
 int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 {
        struct virtio_net_parameters net_params;
index 4fbb2683f009c06318483c858f76d6850f7d34c0..2138e7b990bb9e355999af777d5a92ae8a36f2a2 100644 (file)
@@ -2,18 +2,10 @@
 
 /* user defined header files */
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-help.h>
-#include <kvm/kvm-run.h>
 
 static int handle_kvm_command(int argc, char **argv)
 {
-       struct cmd_struct command[] = {
-               { "help",  kvm_cmd_help,  0 },
-               { "run",   kvm_cmd_run,   0 },
-               { NULL,    NULL,          0 },
-       };
-
-       return handle_command(command, argc, (const char **) &argv[0]);
+       return handle_command(kvm_commands, argc, (const char **) &argv[0]);
 }
 
 int main(int argc, char *argv[])