]> xenbits.xensource.com Git - xen.git/commitdiff
xl: wrap help output if command name is too long
authorIan Campbell <ian.campbell@citrix.com>
Thu, 6 Oct 2011 16:18:38 +0000 (17:18 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 6 Oct 2011 16:18:38 +0000 (17:18 +0100)
Without this in the "xl help" line for pci-list-assignable-devices the command
name merges with the first word of the help. Since the bash completion support
parses "xl help" this leads to "pci-list-assignable-devicesList" being
presented as an option instead of the correct command name.

We also need to filter out lines which start with more than one space in the
bash completion support to stop "List" appearing as a possible command name
after the change to wrap it.

Doesn't address the fact that some help text overflows 80 columns.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/bash-completion
tools/libxl/xl_cmdimpl.c

index b184f7494d2d3f451c9b53cd057b5cec8dc1aaaf..513d28e9b63a268fbb3d98436b42047f9b1ba894 100644 (file)
@@ -11,7 +11,7 @@ _xl()
        xl=xl
 
        if [[ $COMP_CWORD == 1 ]] ; then
-               opts=`${xl} help 2>/dev/null | sed '1,4d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+               opts=`${xl} help 2>/dev/null | sed '1,4d' | awk '/^ [^ ]/ {print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                return 0
        fi
 
index 8d20647979e46ee0371f585f6caf475117edad06..99e3c49e973faf24b856871e52f7be6d31081df4 100644 (file)
@@ -1728,9 +1728,12 @@ void help(const char *command)
     if (!command || !strcmp(command, "help")) {
         printf("Usage xl [-vN] <subcommand> [args]\n\n");
         printf("xl full list of subcommands:\n\n");
-        for (i = 0; i < cmdtable_len; i++)
-            printf(" %-20s%s\n",
-                   cmd_table[i].cmd_name, cmd_table[i].cmd_desc);
+        for (i = 0; i < cmdtable_len; i++) {
+            printf(" %-19s ", cmd_table[i].cmd_name);
+            if (strlen(cmd_table[i].cmd_name) > 19)
+                printf("\n %-19s ", "");
+            printf("%s\n", cmd_table[i].cmd_desc);
+        }
     } else {
         cmd = cmdtable_lookup(command);
         if (cmd) {