[lxc-devel] [PATCH] lxc-ls: Update help message to include fields

Stéphane Graber stgraber at ubuntu.com
Fri Mar 7 21:30:13 UTC 2014


Instead of maintaining hardcoded lists, point everyone to --help and
have the current list of valid and default fields printed there.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 doc/lxc-ls.sgml.in |  3 +--
 src/lxc/lxc-ls.in  | 10 ++++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/doc/lxc-ls.sgml.in b/doc/lxc-ls.sgml.in
index 37e356c..1c40d33 100644
--- a/doc/lxc-ls.sgml.in
+++ b/doc/lxc-ls.sgml.in
@@ -145,8 +145,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
         <listitem>
           <para>
             Comma separate list of column to show in the fancy output.
-            Valid values are: name, state, ipv4, ipv6 and pid
-            Default is: name,state,ipv4,ipv6
+            The list of accepted and default fields is listed in --help.
           </para>
         </listitem>
       </varlistentry>
diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
index 0f81391..7e35ab2 100755
--- a/src/lxc/lxc-ls.in
+++ b/src/lxc/lxc-ls.in
@@ -104,10 +104,16 @@ def get_root_path(path):
 # Constants
 FIELDS = ("name", "state", "ipv4", "ipv6", "autostart", "pid",
           "memory", "ram", "swap")
+DEFAULT_FIELDS = ("name", "state", "ipv4", "ipv6", "autostart")
 
 # Begin parsing the command line
 parser = argparse.ArgumentParser(description=_("LXC: List containers"),
-                                 formatter_class=argparse.RawTextHelpFormatter)
+                                 formatter_class=argparse.RawTextHelpFormatter,
+                                 epilog=_("""Valid fancy-format fields:
+  %s
+
+Default fancy-format fields:
+  %s\n""" % (", ".join(FIELDS), ", ".join(DEFAULT_FIELDS))))
 
 parser.add_argument("-1", dest="one", action="store_true",
                     help=_("list one container per line (default when piped)"))
@@ -132,7 +138,7 @@ parser.add_argument("-f", "--fancy", action="store_true",
                     help=_("use fancy output"))
 
 parser.add_argument("-F", "--fancy-format", type=str,
-                    default="name,state,ipv4,ipv6,autostart",
+                    default=",".join(DEFAULT_FIELDS),
                     help=_("comma separated list of fields to show"))
 
 parser.add_argument("--nesting", dest="nesting", action="store_true",
-- 
1.9.0



More information about the lxc-devel mailing list