* [Patch] kvm tools: implement "help xxx" command
@ 2011-05-20 7:01 Amerigo Wang
2011-05-20 7:30 ` Pekka Enberg
0 siblings, 1 reply; 3+ messages in thread
From: Amerigo Wang @ 2011-05-20 7:01 UTC (permalink / raw)
To: kvm; +Cc: penberg, mingo, WANG Cong
'kvm run --help' works fine but 'kvm help run' shows nothing,
this patch implements it.
Signed-off-by: WANG Cong <amwang@redhat.com>
---
diff --git a/tools/kvm/include/kvm/kvm-cmd.h b/tools/kvm/include/kvm/kvm-cmd.h
index 8d5fca5..0a73bce 100644
--- a/tools/kvm/include/kvm/kvm-cmd.h
+++ b/tools/kvm/include/kvm/kvm-cmd.h
@@ -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
diff --git a/tools/kvm/include/kvm/kvm-run.h b/tools/kvm/include/kvm/kvm-run.h
index 13104e2..d056ad4 100644
--- a/tools/kvm/include/kvm/kvm-run.h
+++ b/tools/kvm/include/kvm/kvm-run.h
@@ -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
diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index b63e033..e545d14 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -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;
diff --git a/tools/kvm/kvm-help.c b/tools/kvm/kvm-help.c
index 5506807..817e4f8 100644
--- a/tools/kvm/kvm-help.c
+++ b/tools/kvm/kvm-help.c
@@ -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;
}
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index c01517f..f5a1790 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -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;
diff --git a/tools/kvm/main.c b/tools/kvm/main.c
index 4fbb268..2138e7b 100644
--- a/tools/kvm/main.c
+++ b/tools/kvm/main.c
@@ -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[])
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Patch] kvm tools: implement "help xxx" command
2011-05-20 7:01 [Patch] kvm tools: implement "help xxx" command Amerigo Wang
@ 2011-05-20 7:30 ` Pekka Enberg
2011-05-20 10:12 ` Prasad Joshi
0 siblings, 1 reply; 3+ messages in thread
From: Pekka Enberg @ 2011-05-20 7:30 UTC (permalink / raw)
To: Amerigo Wang
Cc: kvm, mingo, Prasad Joshi, Sasha Levin, Cyrill Gorcunov, Asias He
On Fri, May 20, 2011 at 10:01 AM, Amerigo Wang <amwang@redhat.com> wrote:
> 'kvm run --help' works fine but 'kvm help run' shows nothing,
> this patch implements it.
>
> Signed-off-by: WANG Cong <amwang@redhat.com>
Looks good to me. Prasad?
> ---
> diff --git a/tools/kvm/include/kvm/kvm-cmd.h b/tools/kvm/include/kvm/kvm-cmd.h
> index 8d5fca5..0a73bce 100644
> --- a/tools/kvm/include/kvm/kvm-cmd.h
> +++ b/tools/kvm/include/kvm/kvm-cmd.h
> @@ -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
> diff --git a/tools/kvm/include/kvm/kvm-run.h b/tools/kvm/include/kvm/kvm-run.h
> index 13104e2..d056ad4 100644
> --- a/tools/kvm/include/kvm/kvm-run.h
> +++ b/tools/kvm/include/kvm/kvm-run.h
> @@ -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
> diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
> index b63e033..e545d14 100644
> --- a/tools/kvm/kvm-cmd.c
> +++ b/tools/kvm/kvm-cmd.c
> @@ -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;
> diff --git a/tools/kvm/kvm-help.c b/tools/kvm/kvm-help.c
> index 5506807..817e4f8 100644
> --- a/tools/kvm/kvm-help.c
> +++ b/tools/kvm/kvm-help.c
> @@ -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;
> }
> diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
> index c01517f..f5a1790 100644
> --- a/tools/kvm/kvm-run.c
> +++ b/tools/kvm/kvm-run.c
> @@ -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;
> diff --git a/tools/kvm/main.c b/tools/kvm/main.c
> index 4fbb268..2138e7b 100644
> --- a/tools/kvm/main.c
> +++ b/tools/kvm/main.c
> @@ -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[])
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] kvm tools: implement "help xxx" command
2011-05-20 7:30 ` Pekka Enberg
@ 2011-05-20 10:12 ` Prasad Joshi
0 siblings, 0 replies; 3+ messages in thread
From: Prasad Joshi @ 2011-05-20 10:12 UTC (permalink / raw)
To: Pekka Enberg
Cc: Amerigo Wang, kvm, mingo, Sasha Levin, Cyrill Gorcunov, Asias He
On Fri, May 20, 2011 at 8:30 AM, Pekka Enberg <penberg@kernel.org> wrote:
> On Fri, May 20, 2011 at 10:01 AM, Amerigo Wang <amwang@redhat.com> wrote:
>> 'kvm run --help' works fine but 'kvm help run' shows nothing,
>> this patch implements it.
>>
>> Signed-off-by: WANG Cong <amwang@redhat.com>
>
> Looks good to me. Prasad?
Ya nice.
Thanks Amerigo.
>
>> ---
>> diff --git a/tools/kvm/include/kvm/kvm-cmd.h b/tools/kvm/include/kvm/kvm-cmd.h
>> index 8d5fca5..0a73bce 100644
>> --- a/tools/kvm/include/kvm/kvm-cmd.h
>> +++ b/tools/kvm/include/kvm/kvm-cmd.h
>> @@ -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
>> diff --git a/tools/kvm/include/kvm/kvm-run.h b/tools/kvm/include/kvm/kvm-run.h
>> index 13104e2..d056ad4 100644
>> --- a/tools/kvm/include/kvm/kvm-run.h
>> +++ b/tools/kvm/include/kvm/kvm-run.h
>> @@ -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
>> diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
>> index b63e033..e545d14 100644
>> --- a/tools/kvm/kvm-cmd.c
>> +++ b/tools/kvm/kvm-cmd.c
>> @@ -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;
>> diff --git a/tools/kvm/kvm-help.c b/tools/kvm/kvm-help.c
>> index 5506807..817e4f8 100644
>> --- a/tools/kvm/kvm-help.c
>> +++ b/tools/kvm/kvm-help.c
>> @@ -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;
>> }
>> diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
>> index c01517f..f5a1790 100644
>> --- a/tools/kvm/kvm-run.c
>> +++ b/tools/kvm/kvm-run.c
>> @@ -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;
>> diff --git a/tools/kvm/main.c b/tools/kvm/main.c
>> index 4fbb268..2138e7b 100644
>> --- a/tools/kvm/main.c
>> +++ b/tools/kvm/main.c
>> @@ -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[])
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-05-20 10:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-20 7:01 [Patch] kvm tools: implement "help xxx" command Amerigo Wang
2011-05-20 7:30 ` Pekka Enberg
2011-05-20 10:12 ` Prasad Joshi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.