# HG changeset patch
# User Wei Yongjun <yjwei@xxxxxxxxxxxxxx>
# Date 1273544009 -28800
# Node ID 3b082b6199edbe1af1c61c778d44028c499e5320
# Parent f8f668ad3841f7596c5085546961d9c7acf53ace
xl: use help table to describe command help information
This patch generate a help table to describe command help
information.
Signed-off-by: Wei Yongjun <yjwei@xxxxxxxxxxxxxx>
diff -r f8f668ad3841 -r 3b082b6199ed tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon May 10 14:50:48 2010 +0800
+++ b/tools/libxl/xl_cmdimpl.c Tue May 11 10:13:29 2010 +0800
@@ -1164,111 +1164,16 @@
for (i = 0; i < cmdtable_len; i++)
printf(" %-20s%s\n",
cmd_table[i].cmd_name, cmd_table[i].cmd_desc);
- } else if(!strcmp(command, "create")) {
- printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
- printf("Create a domain based on <ConfigFile>.\n\n");
- printf("Options:\n\n");
- printf("-h Print this help.\n");
- printf("-p Leave the domain paused after it is
created.\n");
- printf("-c Connect to the console after the domain
is created.\n");
- printf("-d Enable debug messages.\n");
- printf("-e Do not wait in the background for the
death of the domain.\n");
- } else if(!strcmp(command, "list")) {
- printf("Usage: xl list [-v] [Domain]\n\n");
- printf("List information about all/some domains.\n\n");
- } else if(!strcmp(command, "pci-attach")) {
- printf("Usage: xl pci-attach <Domain> <BDF> [Virtual Slot]\n\n");
- printf("Insert a new pass-through pci device.\n\n");
- } else if(!strcmp(command, "pci-detach")) {
- printf("Usage: xl pci-detach <Domain> <BDF>\n\n");
- printf("Remove a domain's pass-through pci device.\n\n");
- } else if(!strcmp(command, "pci-list")) {
- printf("Usage: xl pci-list <Domain>\n\n");
- printf("List pass-through pci devices for a domain.\n\n");
- } else if(!strcmp(command, "pause")) {
- printf("Usage: xl pause <Domain>\n\n");
- printf("Pause execution of a domain.\n\n");
- } else if(!strcmp(command, "unpause")) {
- printf("Usage: xl unpause <Domain>\n\n");
- printf("Unpause a paused domain.\n\n");
- } else if(!strcmp(command, "save")) {
- printf("Usage: xl save [options] <Domain> <CheckpointFile>
[<ConfigFile>]\n\n");
- printf("Save a domain state to restore later.\n\n");
- printf("Options:\n\n");
- printf("-h Print this help.\n");
- printf("-c Leave domain running after creating the
snapshot.\n");
- } else if(!strcmp(command, "restore")) {
- printf("Usage: xl restore [options] [<ConfigFile>]
<CheckpointFile>\n\n");
- printf("Restore a domain from a saved state.\n\n");
- printf("Options:\n\n");
- printf("-h Print this help.\n");
- printf("-p Do not unpause domain after restoring
it.\n");
- printf("-e Do not wait in the background for the
death of the domain.\n");
- printf("-d Enable debug messages.\n");
- } else if(!strcmp(command, "migrate")) {
- printf("Usage: xl migrate [options] <Domain> <host>\n\n");
- printf("Save a domain state to restore later.\n\n");
- printf("Options:\n\n");
- printf("-h Print this help.\n");
- printf("-C <config> Send <config> instead of config file
from creation.\n");
- printf("-s <sshcommand> Use <sshcommand> instead of ssh.
String will be passed to sh. If empty, run <host> instead of ssh <host> xl
migrate-receive [-d -e]\n");
- printf("-e Do not wait in the background (on
<host>) for the death of the domain.\n");
- } else if(!strcmp(command, "migrate-receive")) {
- printf("Usage: xl migrate-receive - for internal use only");
- } else if(!strcmp(command, "restore")) {
- printf("Usage: xl restore [options] [<ConfigFile>]
<CheckpointFile>\n\n");
- printf("Restore a domain from a saved state.\n\n");
- printf("Options:\n\n");
- printf("-h Print this help.\n");
- printf("-O Old (configless) xl save format.\n");
- printf("-p Do not unpause domain after restoring
it.\n");
- printf("-e Do not wait in the background for the
death of the domain.\n");
- } else if(!strcmp(command, "destroy")) {
- printf("Usage: xl destroy <Domain>\n\n");
- printf("Terminate a domain immediately.\n\n");
- } else if (!strcmp(command, "console")) {
- printf("Usage: xl console <Domain>\n\n");
- printf("Attach to domain's console.\n\n");
- } else if (!strcmp(command, "cd-insert")) {
- printf("Usage: xl cd-insert <Domain> <VirtualDevice> <type:path>\n\n");
- printf("Insert a cdrom into a guest's cd drive.\n\n");
- } else if (!strcmp(command, "cd-eject")) {
- printf("Usage: xl cd-eject <Domain> <VirtualDevice>\n\n");
- printf("Eject a cdrom from a guest's cd drive.\n\n");
- } else if (!strcmp(command, "mem-set")) {
- printf("Usage: xl mem-set <Domain> <MemKB>\n\n");
- printf("Set the current memory usage for a domain.\n\n");
- } else if (!strcmp(command, "button-press")) {
- printf("Usage: xl button-press <Domain> <Button>\n\n");
- printf("Indicate <Button> press to a domain.\n");
- printf("<Button> may be 'power' or 'sleep'.\n\n");
- } else if (!strcmp(command, "vcpu-list")) {
- printf("Usage: xl vcpu-list [Domain, ...]\n\n");
- printf("List the VCPUs for all/some domains.\n\n");
- } else if (!strcmp(command, "vcpu-pin")) {
- printf("Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n");
- printf("Set which CPUs a VCPU can use.\n\n");
- } else if (!strcmp(command, "vcpu-set")) {
- printf("Usage: xl vcpu-set <Domain> <vCPUs>\n\n");
- printf("Set the number of active VCPUs for allowed for the
domain.\n\n");
- } else if(!strcmp(command, "info")) {
- printf("Usage: xl info\n\n");
- printf("Get information about Xen host.\n\n");
- } else if (!strcmp(command, "sched-credit")) {
- printf("Usage: xl sched-credit [-d <Domain>
[-w[=WEIGHT]|-c[=CAP]]]\n\n");
- printf("Get/set credit scheduler parameters.\n");
- printf(" -d DOMAIN, --domain=DOMAIN Domain to modify\n");
- printf(" -w WEIGHT, --weight=WEIGHT Weight (int)\n");
- printf(" -c CAP, --cap=CAP Cap (int)\n");
- } else if (!strcmp(command, "domid")) {
- printf("Usage: xl domid <DomainName>\n\n");
- printf("Convert a domain name to domain id.\n");
- } else if (!strcmp(command, "domname")) {
- printf("Usage: xl domname <DomainId>\n\n");
- printf("Convert a domain id to domain name.\n");
- } else if (!strcmp(command, "rename")) {
- printf("Usage: xl rename <Domain> <NewDomainName>\n\n");
- printf("Rename a domain.\n");
+ } else {
+ for (i = 0; i < cmdtable_len; i++)
+ if (!strcmp(command, cmd_table[i].cmd_name)) {
+ printf("%s\n%s.\n\n", cmd_table[i].cmd_usage,
cmd_table[i].cmd_desc);
+ if (cmd_table[i].cmd_option)
+ printf("%s", cmd_table[i].cmd_option);
+ return;
+ }
+
+ printf("command not implemented\n");
}
}
diff -r f8f668ad3841 -r 3b082b6199ed tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Mon May 10 14:50:48 2010 +0800
+++ b/tools/libxl/xl_cmdtable.c Tue May 11 10:13:29 2010 +0800
@@ -15,32 +15,162 @@
#include "xl_cmdtable.h"
struct cmd_spec cmd_table[] = {
- { "create", &main_create, "create a domain from config file <filename>" },
- { "list", &main_list, "list information about all domains" },
- { "destroy", &main_destroy, "terminate a domain immediately" },
- { "pci-attach", &main_pciattach, "insert a new pass-through pci device" },
- { "pci-detach", &main_pcidetach, "remove a domain's pass-through pci
device" },
- { "pci-list", &main_pcilist, "list pass-through pci devices for a domain"
},
- { "pause", &main_pause, "pause execution of a domain" },
- { "unpause", &main_unpause, "unpause a paused domain" },
- { "console", &main_console, "attach to domain's console" },
- { "save", &main_save, "save a domain state to restore later" },
- { "migrate", &main_migrate, "save a domain state to restore later" },
- { "restore", &main_restore, "restore a domain from a saved state" },
- { "migrate-receive", &main_migrate_receive, "restore a domain from a saved
state" },
- { "cd-insert", &main_cd_insert, "insert a cdrom into a guest's cd drive" },
- { "cd-eject", &main_cd_eject, "eject a cdrom from a guest's cd drive" },
- { "mem-set", &main_memset, "set the current memory usage for a domain" },
- { "button-press", &main_button_press, "indicate an ACPI button press to
the domain" },
- { "vcpu-list", &main_vcpulist, "list the VCPUs for all/some domains" },
- { "vcpu-pin", &main_vcpupin, "set which CPUs a VCPU can use" },
- { "vcpu-set", &main_vcpuset, "set the number of active VCPUs allowed for
the domain" },
- { "list-vm", &main_list_vm, "list the VMs,without DOM0" },
- { "info", &main_info, "get information about Xen host" },
- { "sched-credit", &main_sched_credit, "get/set credit scheduler
parameters" },
- { "domid", &main_domid, "convert a domain name to domain id"},
- { "domname", &main_domname, "convert a domain id to domain name"},
- { "rename", &main_rename, "rename a domain"},
+ { "create",
+ &main_create,
+ "Create a domain from config file <filename>",
+ "Usage: xl create <ConfigFile> [options] [vars]\n",
+ "Options:\n\n"
+ "-h Print this help.\n"
+ "-p Leave the domain paused after it is created.\n"
+ "-c Connect to the console after the domain is created.\n"
+ "-d Enable debug messages.\n"
+ "-e Do not wait in the background for the death of the domain.\n"
+ },
+ { "list",
+ &main_list,
+ "List information about all/some domains",
+ "Usage: xl list [-v] [Domain]\n",
+ },
+ { "destroy",
+ &main_destroy,
+ "Terminate a domain immediately",
+ "Usage: xl destroy <Domain>\n",
+ },
+ { "pci-attach",
+ &main_pciattach,
+ "Insert a new pass-through pci device",
+ "Usage: xl pci-attach <Domain> <BDF> [Virtual Slot]\n",
+ },
+ { "pci-detach",
+ &main_pcidetach,
+ "Remove a domain's pass-through pci device",
+ "Usage: xl pci-detach <Domain> <BDF>\n",
+ },
+ { "pci-list",
+ &main_pcilist,
+ "List pass-through pci devices for a domain",
+ "Usage: xl pci-list <Domain>\n",
+ },
+ { "pause",
+ &main_pause,
+ "Pause execution of a domain",
+ "Usage: xl pause <Domain>\n",
+ },
+ { "unpause",
+ &main_unpause,
+ "Unpause a paused domain",
+ "Usage: xl unpause <Domain>\n",
+ },
+ { "console",
+ &main_console,
+ "Attach to domain's console",
+ "Usage: xl console <Domain>\n",
+ },
+ { "save",
+ &main_save,
+ "Save a domain state to restore later",
+ "Usage: xl save [options] <Domain> <CheckpointFile> [<ConfigFile>]\n",
+ "Options:\n\n"
+ "-h Print this help.\n"
+ "-c Leave domain running after creating the snapshot.\n"
+ },
+ { "migrate",
+ &main_migrate,
+ "Save a domain state to restore later",
+ "Usage: xl migrate [options] <Domain> <host>\n",
+ "Options:\n\n"
+ "-h Print this help.\n"
+ "-C <config> Send <config> instead of config file from creation.\n"
+ "-s <sshcommand> Use <sshcommand> instead of ssh. String will be
passed\n"
+ " to sh. If empty, run <host> instead of ssh <host> xl\n"
+ " migrate-receive [-d -e]\n"
+ "-e Do not wait in the background (on <host>) for the
death\n"
+ " of the domain.\n"
+ },
+ { "restore",
+ &main_restore,
+ "Restore a domain from a saved state",
+ "Usage: xl restore [options] [<ConfigFile>] <CheckpointFile>\n",
+ "Options:\n\n"
+ "-h Print this help.\n"
+ "-p Do not unpause domain after restoring it.\n"
+ "-e Do not wait in the background for the death of the domain.\n"
+ "-d Enable debug messages.\n"
+ },
+ { "migrate-receive",
+ &main_migrate_receive,
+ "Restore a domain from a saved state",
+ "Usage: xl migrate-receive - for internal use only\n",
+ },
+ { "cd-insert",
+ &main_cd_insert,
+ "Insert a cdrom into a guest's cd drive",
+ "Usage: xl cd-insert <Domain> <VirtualDevice> <type:path>\n",
+ },
+ { "cd-eject",
+ &main_cd_eject,
+ "Eject a cdrom from a guest's cd drive",
+ "Usage: xl cd-eject <Domain> <VirtualDevice>\n",
+ },
+ { "mem-set",
+ &main_memset,
+ "Set the current memory usage for a domain",
+ "Usage: xl mem-set <Domain> <MemKB>\n",
+ },
+ { "button-press",
+ &main_button_press,
+ "Indicate an ACPI button press to the domain",
+ "Usage: xl button-press <Domain> <Button>\n\n",
+ "<Button> may be 'power' or 'sleep'.\n"
+ },
+ { "vcpu-list",
+ &main_vcpulist,
+ "List the VCPUs for all/some domains",
+ "Usage: xl vcpu-list [Domain, ...]\n",
+ },
+ { "vcpu-pin",
+ &main_vcpupin,
+ "Set which CPUs a VCPU can use",
+ "Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n",
+ },
+ { "vcpu-set",
+ &main_vcpuset,
+ "Set the number of active VCPUs allowed for the domain",
+ "Usage: xl vcpu-set <Domain> <vCPUs>\n",
+ },
+ { "list-vm",
+ &main_list_vm,
+ "List the VMs,without DOM0",
+ "Usage: xl list-vm\n",
+ },
+ { "info",
+ &main_info,
+ "Get information about Xen host",
+ "Usage: xl info\n",
+ },
+ { "sched-credit",
+ &main_sched_credit,
+ "Get/set credit scheduler parameters",
+ "Usage: xl sched-credit [-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]\n",
+ " -d DOMAIN, --domain=DOMAIN Domain to modify\n"
+ " -w WEIGHT, --weight=WEIGHT Weight (int)\n"
+ " -c CAP, --cap=CAP Cap (int)\n"
+ },
+ { "domid",
+ &main_domid,
+ "Convert a domain name to domain id",
+ "Usage: xl domid <DomainName>\n",
+ },
+ { "domname",
+ &main_domname,
+ "Convert a domain id to domain name",
+ "Usage: xl domname <DomainId>\n",
+ },
+ { "rename",
+ &main_rename,
+ "Rename a domain",
+ "Usage: xl rename <Domain> <NewDomainName>\n",
+ },
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
diff -r f8f668ad3841 -r 3b082b6199ed tools/libxl/xl_cmdtable.h
--- a/tools/libxl/xl_cmdtable.h Mon May 10 14:50:48 2010 +0800
+++ b/tools/libxl/xl_cmdtable.h Tue May 11 10:13:29 2010 +0800
@@ -18,6 +18,8 @@
char *cmd_name;
int (*cmd_impl)(int argc, char **argv);
char *cmd_desc;
+ char *cmd_usage;
+ char *cmd_option;
};
extern struct cmd_spec cmd_table[];
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|