aboutsummaryrefslogtreecommitdiffstats
path: root/builtin-help.c
blob: 5970fb7484f629646bdcef69772dd10c876fd020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>

/* user defined headers */
#include <common-cmds.h>

#include <kvm/util.h>
#include <kvm/kvm-cmd.h>
#include <kvm/builtin-help.h>
#include <kvm/kvm.h>


const char kvm_usage_string[] =
	"lkvm COMMAND [ARGS]";

const char kvm_more_info_string[] =
	"See 'lkvm help COMMAND' for more information on a specific command.";


static void list_common_cmds_help(void)
{
	unsigned int i, longest = 0;

	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
		if (longest < strlen(common_cmds[i].name))
			longest = strlen(common_cmds[i].name);
	}

	puts(" The most commonly used lkvm commands are:");
	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
		printf("   %-*s   ", longest, common_cmds[i].name);
		puts(common_cmds[i].help);
	}
}

static void kvm_help(void)
{
	printf("\n To start a simple non-privileged shell run '%s run'\n\n"
		"usage: %s\n\n", KVM_BINARY_NAME, 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) {
		kvm_help();
		return 0;
	}
	help_cmd(argv[0]);
	return 0;
}