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
#define __KVM_RUN_H__
int kvm_cmd_run(int argc, const char **argv, const char *prefix);
+void kvm_run_help(void);
#endif
/* 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
* 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;
#include <common-cmds.h>
#include <kvm/util.h>
+#include <kvm/kvm-cmd.h>
#include <kvm/kvm-help.h>
}
}
+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;
}
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;
/* 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[])