diff mbox series

[WIP,14/16] WIP: tools/xl: Enhance "list" command

Message ID 23d48471e5f987736525b4d2be71419953fd4698.1608663694.git.ehem+xen@m5p.com (mailing list archive)
State New, archived
Headers show
Series Addition of formatting options to `xl list` subcommands | expand

Commit Message

Elliott Mitchell Dec. 9, 2020, 10:34 p.m. UTC
Add several features to specify output.  Allow omitting potentially
unneeded lines and add argument for exact line format.

Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com>
---
 tools/xl/xl_cmdtable.c |  2 ++
 tools/xl/xl_list.c     | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index f44c65a3f8..91c2026bc8 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -53,6 +53,7 @@  struct cmd_spec cmd_table[] = {
       &main_list, 0, 0,
       "List information about all/some domains",
       "[options] [Domain]\n",
+      "-0, --no-domain0        Omit information for Domain 0\n"
       "-F, --format            Specify output format string\n"
       "   Similar to printf(3) formatting, conversion characters are:\n"
       "      %A    NODE Affinity\n"
@@ -67,6 +68,7 @@  struct cmd_spec cmd_table[] = {
       "      %t    Time(s)\n"
       "      %u    UUID\n"
       "      %v    vCPUs\n"
+      "-H, --no-header         Omit table header\n"
       "-Z, --context           Prints out security context\n"
       "-c, --cpupool           Prints the cpupool the domain is in\n"
       "-l, --long              Output all VM details\n"
diff --git a/tools/xl/xl_list.c b/tools/xl/xl_list.c
index 3ed6da8feb..49ff2acaad 100644
--- a/tools/xl/xl_list.c
+++ b/tools/xl/xl_list.c
@@ -397,6 +397,8 @@  int main_list(int argc, char **argv)
     bool context = false;
     bool cpupool = false;
     bool details = false;
+    bool dom0 = true;
+    bool header = true;
     const char *formatstr = NULL;
     bool numa = false;
     bool verbose = false;
@@ -405,6 +407,8 @@  int main_list(int argc, char **argv)
         {"cpupool", 0, 0, 'c'},
         {"format", 0, 0, 'F'},
         {"long", 0, 0, 'l'},
+        {"no-domain0", 0, 0, '0'},
+        {"no-header", 0, 0, 'H'},
         {"numa", 0, 0, 'n'},
         {"verbose", 0, 0, 'v'},
         COMMON_LONG_OPTS
@@ -414,10 +418,16 @@  int main_list(int argc, char **argv)
     libxl_dominfo *info, *info_free=0;
     int nb_domain, rc;
 
-    SWITCH_FOREACH_OPT(opt, "F:Zchlnv", opts, "list", 0) {
+    SWITCH_FOREACH_OPT(opt, "0F:HZchlnv", opts, "list", 0) {
+    case '0':
+        dom0 = false;
+        break;
     case 'F':
         formatstr = optarg;
         break;
+    case 'H':
+        header = false;
+        break;
     case 'Z':
         context = true;
         break;
@@ -476,10 +486,10 @@  int main_list(int argc, char **argv)
             return EXIT_FAILURE;
         }
 
-        format(formats, formatstr, NULL);
+        if (header) format(formats, formatstr, NULL);
 
         while (nb_domain) {
-            format(formats, formatstr, info);
+            if (info->domid || dom0) format(formats, formatstr, info);
             ++info;
             --nb_domain;
         }