xref: /kvmtool/builtin-help.c (revision ac41895e11e422292c1c150f418fec34910d4680)
1 #include <stdio.h>
2 #include <string.h>
3 
4 /* user defined headers */
5 #include <common-cmds.h>
6 
7 #include <kvm/util.h>
8 #include <kvm/kvm-cmd.h>
9 #include <kvm/builtin-help.h>
10 
11 
12 const char kvm_usage_string[] =
13 	"kvm COMMAND [ARGS]";
14 
15 const char kvm_more_info_string[] =
16 	"See 'kvm help COMMAND' for more information on a specific command.";
17 
18 
19 static void list_common_cmds_help(void)
20 {
21 	unsigned int i, longest = 0;
22 
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);
26 	}
27 
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);
32 	}
33 }
34 
35 static void kvm_help(void)
36 {
37 	printf("\n To start a simple non-privileged shell run 'kvm run'\n\n"
38 		"usage: %s\n\n", kvm_usage_string);
39 	list_common_cmds_help();
40 	printf("\n %s\n\n", kvm_more_info_string);
41 }
42 
43 
44 static void help_cmd(const char *cmd)
45 {
46 	struct cmd_struct *p;
47 	p = kvm_get_command(kvm_commands, cmd);
48 	if (!p)
49 		kvm_help();
50 	else if (p->help)
51 		p->help();
52 }
53 
54 int kvm_cmd_help(int argc, const char **argv, const char *prefix)
55 {
56 	if (!argv || !*argv) {
57 		kvm_help();
58 		return 0;
59 	}
60 	help_cmd(argv[0]);
61 	return 0;
62 }
63