WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xl: use help table to describe command help informat

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] xl: use help table to describe command help information
From: Wei Yongjun <yjwei@xxxxxxxxxxxxxx>
Date: Mon, 10 May 2010 15:10:43 +0800
Delivery-date: Mon, 10 May 2010 00:13:23 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4BE7B0E3.5030604@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <4BE7B0E3.5030604@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4
This patch generate a help table to describe command help
information.

Signed-off-by: Wei Yongjun <yjwei@xxxxxxxxxxxxxx>

diff -r ac61c50eb031 -r 9530370da103 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  Mon May 10 15:03:03 2010 +0800
@@ -1164,111 +1164,15 @@
         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; cmd_htable[i].cmd_name != NULL; i++)
+            if (!strcmp(command, cmd_htable[i].cmd_name)) {
+                printf("%s", cmd_htable[i].cmd_help);
+                break;
+            }
+
+        if (!cmd_htable[i].cmd_name)
+            printf("no help information for command %s\n", command);
     }
 }
 
diff -r ac61c50eb031 -r 9530370da103 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 Mon May 10 15:03:03 2010 +0800
@@ -14,6 +14,142 @@
 
 #include "xl_cmdtable.h"
 
+struct cmd_help cmd_htable[] = {
+    { "create", 
+        "Usage: xl create <ConfigFile> [options] [vars]\n\n"
+        "Create a domain based on <ConfigFile>.\n\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",
+        "Usage: xl list [-v] [Domain]\n\n"
+        "List information about all/some domains.\n\n"
+    },
+    { "pci-attach",
+        "Usage: xl pci-attach <Domain> <BDF> [Virtual Slot]\n\n"
+        "Insert a new pass-through pci device.\n\n"
+    },
+    { "pci-detach",
+        "Usage: xl pci-detach <Domain> <BDF>\n\n"
+        "Remove a domain's pass-through pci device.\n\n"
+    },
+    { "pci-list",
+        "Usage: xl pci-list <Domain>\n\n"
+        "List pass-through pci devices for a domain.\n\n"
+    },
+    { "pause",
+        "Usage: xl pause <Domain>\n\n"
+        "Pause execution of a domain.\n\n"
+    },
+    { "unpause",
+        "Usage: xl unpause <Domain>\n\n"
+        "Unpause a paused domain.\n\n"
+    },
+    { "save",
+        "Usage: xl save [options] <Domain> <CheckpointFile> [<ConfigFile>]\n\n"
+        "Save a domain state to restore later.\n\n"
+        "Options:\n\n"
+        "-h                     Print this help.\n"
+        "-c                     Leave domain running after creating the 
snapshot.\n"
+    },
+    { "restore",
+        "Usage: xl restore [options] [<ConfigFile>] <CheckpointFile>\n\n"
+        "Restore a domain from a saved state.\n\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",
+        "Usage: xl migrate [options] <Domain> <host>\n\n"
+        "Save a domain state to restore later.\n\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 to sh."
+        "  If empty, run <host> instead of ssh <host> xl migrate-receive [-d 
-e]\n"
+        "-e                     Do not wait in the background (on <host>) for 
the death of the domain.\n"
+    },
+    { "migrate-receive",
+        "Usage: xl migrate-receive  - for internal use only"
+    },
+    { "restore",
+        "Usage: xl restore [options] [<ConfigFile>] <CheckpointFile>\n\n"
+        "Restore a domain from a saved state.\n\n"
+        "Options:\n\n"
+        "-h                     Print this help.\n"
+        "-O                     Old (configless) xl save format.\n"
+        "-p                     Do not unpause domain after restoring it.\n"
+        "-e                     Do not wait in the background for the death of 
the domain.\n"
+    },
+    { "destroy",
+        "Usage: xl destroy <Domain>\n\n"
+        "Terminate a domain immediately.\n\n"
+    },
+    { "console",
+        "Usage: xl console <Domain>\n\n"
+        "Attach to domain's console.\n\n"
+    },
+    { "cd-insert",
+        "Usage: xl cd-insert <Domain> <VirtualDevice> <type:path>\n\n"
+        "Insert a cdrom into a guest's cd drive.\n\n"
+    },
+    { "cd-eject",
+        "Usage: xl cd-eject <Domain> <VirtualDevice>\n\n"
+        "Eject a cdrom from a guest's cd drive.\n\n"
+    },
+    { "mem-set",
+        "Usage: xl mem-set <Domain> <MemKB>\n\n"
+        "Set the current memory usage for a domain.\n\n"
+    },
+    { "button-press",
+        "Usage: xl button-press <Domain> <Button>\n\n"
+        "Indicate <Button> press to a domain.\n"
+        "<Button> may be 'power' or 'sleep'.\n\n"
+    },
+    { "vcpu-list",
+        "Usage: xl vcpu-list [Domain, ...]\n\n"
+        "List the VCPUs for all/some domains.\n\n"
+    },
+    { "vcpu-pin",
+        "Usage: xl vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n"
+        "Set which CPUs a VCPU can use.\n\n"
+    },
+    { "vcpu-set",
+        "Usage: xl vcpu-set <Domain> <vCPUs>\n\n"
+        "Set the number of active VCPUs for allowed for the domain.\n\n"
+    },
+    { "info",
+        "Usage: xl info\n\n"
+        "Get information about Xen host.\n\n"
+    },
+    { "sched-credit",
+        "Usage: xl sched-credit [-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]\n\n"
+        "Get/set credit scheduler parameters.\n"
+        "  -d DOMAIN, --domain=DOMAIN     Domain to modify\n"
+        "  -w WEIGHT, --weight=WEIGHT     Weight (int)\n" 
+        "  -c CAP, --cap=CAP              Cap (int)\n"
+    },
+    { "domid",
+        "Usage: xl domid <DomainName>\n\n"
+        "Convert a domain name to domain id.\n"
+    },
+    { "domname",
+        "Usage: xl domname <DomainId>\n\n"
+        "Convert a domain id to domain name.\n"
+    },
+    { "rename",
+        "Usage: xl rename <Domain> <NewDomainName>\n\n"
+        "Rename a domain.\n"
+    },
+    { /* NULL */ },
+};
+
 struct cmd_spec cmd_table[] = {
     { "create", &main_create, "create a domain from config file <filename>" },
     { "list", &main_list, "list information about all domains" },
diff -r ac61c50eb031 -r 9530370da103 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 Mon May 10 15:03:03 2010 +0800
@@ -14,11 +14,17 @@
 
 #include "xl_cmdimpl.h"
 
+struct cmd_help {
+    char *cmd_name;
+    char *cmd_help;
+};
+
 struct cmd_spec {
     char *cmd_name;
     int (*cmd_impl)(int argc, char **argv);
     char *cmd_desc;
 };
 
+extern struct cmd_help cmd_htable[];
 extern struct cmd_spec cmd_table[];
 extern int cmdtable_len;


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel