From c1a0370daac622a5590b516827326d6340872251 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Fri, 3 Jul 2015 23:38:14 +0200 Subject: [PATCH] Config: Make json.array default to "on" - This makes the default "export" output work out of the box with most JSON parsing libraries. --- ChangeLog | 2 ++ doc/man/taskrc.5.in | 9 ++++++--- src/Config.cpp | 2 +- test/export.t | 2 +- test/export.yaml.t | 3 ++- test/roundtrip.t | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 634528877..aa5402d4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ - Enable "task sync" support by default. "cmake -DENABLE_SYNC=OFF" allows disabling it and building Taskwarrior without libgnutls available. - An attempt to add or remove a virtual tag is now an error (thanks to Scott M). +- json.array now defaults to "on", making "export" output a JSON array that + can be parsed by most JSON libraries without changes. ------ current release --------------------------- diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index 35fe0d126..b7b6d4700 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -394,9 +394,12 @@ Enables or disables access to Taskwarrior internals and task metadata on the command line. Defaults to on. .TP -.B json.array=off -Determines whether the query command encloses the JSON output in '[...]' to -create a properly-formed JSON array. Defaults to off. +.B json.array=on +Determines whether the export command encloses the JSON output in '[...]' and +adds ',' after each exported task object to create a properly-formed JSON +array. +With json.array=off, export writes raw JSON objects to STDOUT, one per line. +Defaults to on. .TP .B _forcecolor=no diff --git a/src/Config.cpp b/src/Config.cpp index ae7ea6728..b4f448e46 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -106,7 +106,7 @@ std::string Config::_defaults = "xterm.title=no # Sets xterm title for some commands\n" "expressions=infix # Prefer infix over postfix expressions\n" "dom=on # Support DOM access\n" - "json.array=off # Enclose JSON output in [ ]\n" + "json.array=on # Enclose JSON output in [ ]\n" "abbreviation.minimum=2 # Shortest allowed abbreviation\n" "\n" "# Dates\n" diff --git a/test/export.t b/test/export.t index 2d43a035f..8d3e0e0bc 100755 --- a/test/export.t +++ b/test/export.t @@ -48,7 +48,7 @@ class TestExportCommand(TestCase): self.t(('add', 'test')) def export(self, identifier): - return json.loads(self.t((str(identifier), 'export'))[1].strip()) + return json.loads(self.t((str(identifier), 'rc.json.array=off', 'export'))[1].strip()) def assertType(self, value, type): self.assertEqual(isinstance(value, type), True) diff --git a/test/export.yaml.t b/test/export.yaml.t index 5dd45b034..5108e2ddd 100755 --- a/test/export.yaml.t +++ b/test/export.yaml.t @@ -44,7 +44,8 @@ $source_dir =~ s{[^/]+$}{..}; if (open my $fh, '>', $rc) { print $fh "data.location=.\n", - "verbose=no\n"; + "verbose=no\n", + "json.array=off"; close $fh; } diff --git a/test/roundtrip.t b/test/roundtrip.t index e02f5638f..06fa8b3ee 100755 --- a/test/roundtrip.t +++ b/test/roundtrip.t @@ -44,7 +44,8 @@ if (open my $fh, '>', $rc) "verbose=off\n", "confirmation=no\n", "defaultwidth=100\n", - "dateformat=m/d/Y\n"; + "dateformat=m/d/Y\n", + "json.array=off"; close $fh; }