[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xl: use help table to describe command help information



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1273577846 -3600
# Node ID 2b5e14e4c5e57b0064d1c0415d9c4629bd0aac9b
# Parent  60b3417b1499a3cbe28a88d286f1b3c2ac01d5fa
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>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c  |  122 +++---------------------------
 tools/libxl/xl_cmdtable.c |  184 +++++++++++++++++++++++++++++++++++++++-------
 tools/libxl/xl_cmdtable.h |    2 
 3 files changed, 173 insertions(+), 135 deletions(-)

diff -r 60b3417b1499 -r 2b5e14e4c5e5 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue May 11 11:23:54 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue May 11 12:37:26 2010 +0100
@@ -1170,114 +1170,20 @@ void help(char *command)
         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 if (!strcmp(command, "trigger")) {
-        printf("Usage: xm trigger <Domain> <nmi|reset|init|power|sleep> 
[<VCPU>]\n\n");
-        printf("Send a trigger to a domain.\n");
+    } else {
+        for (i = 0; i < cmdtable_len; i++)
+            if (!strcmp(command, cmd_table[i].cmd_name))
+                break;
+        if (i == cmdtable_len) {
+            printf("command not implemented\n");
+        } else {
+            printf("Usage: xl %s %s\n\n%s.\n\n",
+                   cmd_table[i].cmd_name,
+                   cmd_table[i].cmd_usage,
+                   cmd_table[i].cmd_desc);
+            if (cmd_table[i].cmd_option)
+            printf("Options:\n\n%s\n", cmd_table[i].cmd_option);
+        }
     }
 }
 
diff -r 60b3417b1499 -r 2b5e14e4c5e5 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue May 11 11:23:54 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Tue May 11 12:37:26 2010 +0100
@@ -15,33 +15,163 @@
 #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"},
-    { "trigger", &main_trigger, "send a trigger to a domain"},
+    { "create",
+      &main_create,
+      "Create a domain from config file <filename>",
+      "<ConfigFile> [options] [vars]",
+      "-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."
+    },
+    { "list",
+      &main_list,
+      "List information about all/some domains",
+      "[-v] [Domain]",
+    },
+    { "destroy",
+      &main_destroy,
+      "Terminate a domain immediately",
+      "<Domain>",
+    },
+    { "pci-attach",
+      &main_pciattach,
+      "Insert a new pass-through pci device",
+      "<Domain> <BDF> [Virtual Slot]",
+    },
+    { "pci-detach",
+      &main_pcidetach,
+      "Remove a domain's pass-through pci device",
+      "<Domain> <BDF>",
+    },
+    { "pci-list",
+      &main_pcilist,
+      "List pass-through pci devices for a domain",
+      "<Domain>",
+    },
+    { "pause",
+      &main_pause,
+      "Pause execution of a domain",
+      "<Domain>",
+    },
+    { "unpause",
+      &main_unpause,
+      "Unpause a paused domain",
+      "<Domain>",
+    },
+    { "console",
+      &main_console,
+      "Attach to domain's console",
+      "<Domain>",
+    },
+    { "save",
+      &main_save,
+      "Save a domain state to restore later",
+      "[options] <Domain> <CheckpointFile> [<ConfigFile>]",
+      "-h  Print this help.\n"
+      "-c  Leave domain running after creating the snapshot."
+    },
+    { "migrate",
+      &main_migrate,
+      "Save a domain state to restore later",
+      "[options] <Domain> <host>",
+      "-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."
+    },
+    { "restore",
+      &main_restore,
+      "Restore a domain from a saved state",
+      "[options] [<ConfigFile>] <CheckpointFile>",
+      "-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."
+    },
+    { "migrate-receive",
+      &main_migrate_receive,
+      "Restore a domain from a saved state",
+      "- for internal use only",
+    },
+    { "cd-insert",
+      &main_cd_insert,
+      "Insert a cdrom into a guest's cd drive",
+      "<Domain> <VirtualDevice> <type:path>",
+    },
+    { "cd-eject",
+      &main_cd_eject,
+      "Eject a cdrom from a guest's cd drive",
+      "<Domain> <VirtualDevice>",
+    },
+    { "mem-set",
+      &main_memset,
+      "Set the current memory usage for a domain",
+      "<Domain> <MemKB>",
+    },
+    { "button-press",
+      &main_button_press,
+      "Indicate an ACPI button press to the domain",
+      "<Domain> <Button>",
+      "<Button> may be 'power' or 'sleep'."
+    },
+    { "vcpu-list",
+      &main_vcpulist,
+      "List the VCPUs for all/some domains",
+      "[Domain, ...]",
+    },
+    { "vcpu-pin",
+      &main_vcpupin,
+      "Set which CPUs a VCPU can use",
+      "<Domain> <VCPU|all> <CPUs|all>",
+    },
+    { "vcpu-set",
+      &main_vcpuset,
+      "Set the number of active VCPUs allowed for the domain",
+      "<Domain> <vCPUs>",
+    },
+    { "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",
+      "[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]",
+      "-d DOMAIN, --domain=DOMAIN     Domain to modify\n"
+      "-w WEIGHT, --weight=WEIGHT     Weight (int)\n"
+      "-c CAP, --cap=CAP              Cap (int)"
+    },
+    { "domid",
+      &main_domid,
+      "Convert a domain name to domain id",
+      "<DomainName>",
+    },
+    { "domname",
+      &main_domname,
+      "Convert a domain id to domain name",
+      "<DomainId>",
+    },
+    { "rename",
+      &main_rename,
+      "Rename a domain",
+      "<Domain> <NewDomainName>",
+    },
+    { "trigger",
+      &main_trigger,
+      "Send a trigger to a domain",
+      "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
diff -r 60b3417b1499 -r 2b5e14e4c5e5 tools/libxl/xl_cmdtable.h
--- a/tools/libxl/xl_cmdtable.h Tue May 11 11:23:54 2010 +0100
+++ b/tools/libxl/xl_cmdtable.h Tue May 11 12:37:26 2010 +0100
@@ -18,6 +18,8 @@ struct cmd_spec {
     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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.