tools: Add -X option for machine parsable output with separator '|'
authorMartin Schwenke <martin@meltin.net>
Wed, 19 Nov 2014 07:19:50 +0000 (18:19 +1100)
committerMartin Schwenke <martin@meltin.net>
Wed, 10 Dec 2014 04:04:54 +0000 (15:04 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(Imported from commit 7428f809a76044fcbc98fd5f718e331ce183941d)

doc/ctdb.1.xml
tools/ctdb.c

index 07a7ed1be00403d58463ed4f3cfa8bc924ba7ba5..c5d81d8d0e3b425deaacb382f96f40597b20149e 100644 (file)
       </listitem>
       </varlistentry>
 
+      <varlistentry><term>-X</term>
+      <listitem>
+       <para>
+         Produce output in machine readable form for easier parsing
+         by scripts. This uses a field delimiter of '|'.  Not all
+         commands support this option.
+       </para>
+       <para>
+         This is equivalent to "-x|" and avoids some shell quoting
+         issues.
+       </para>
+      </listitem>
+      </varlistentry>
+
       <varlistentry><term>-t <parameter>TIMEOUT</parameter></term>
       <listitem>
        <para>
index cb716c591f44888763365446f1a18fba347de6f9..66794813f7faf7d674952d18f2a6253f8dfa7801 100644 (file)
@@ -6505,6 +6505,7 @@ int main(int argc, const char *argv[])
 {
        struct ctdb_context *ctdb;
        char *nodestring = NULL;
+       int machineparsable = 0;
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
                POPT_CTDB_CMDLINE
@@ -6512,6 +6513,7 @@ int main(int argc, const char *argv[])
                { "node",      'n', POPT_ARG_STRING, &nodestring, 0, "node", "integer|all" },
                { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machine readable output", NULL },
                { NULL, 'x', POPT_ARG_STRING, &options.machineseparator, 0, "specify separator for machine readable output", "char" },
+               { NULL, 'X', POPT_ARG_NONE, &machineparsable, 0, "enable machine parsable output with separator |", NULL },
                { "verbose",    'v', POPT_ARG_NONE, &options.verbose, 0, "enable verbose output", NULL },
                { "maxruntime", 'T', POPT_ARG_INT, &options.maxruntime, 0, "die if runtime exceeds this limit (in seconds)", "integer" },
                { "print-emptyrecords", 0, POPT_ARG_NONE, &options.printemptyrecords, 0, "print the empty records when dumping databases (catdb, cattdb, dumpdbbackup)", NULL },
@@ -6569,6 +6571,9 @@ int main(int argc, const char *argv[])
                }
        }
 
+       if (machineparsable) {
+               options.machineseparator = "|";
+       }
        if (options.machineseparator != NULL) {
                if (strlen(options.machineseparator) != 1) {
                        printf("Invalid separator \"%s\" - "