From c1a21ce5a4c0e8c387be7624e3c99d923ea99e94 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 31 Aug 2011 23:52:07 -0400 Subject: [PATCH] Export YAML - Implemented export-yaml.pl as a filter. - Reimplemented export.yaml.t to use the filter. --- scripts/add-ons/export-yaml.pl | 17 +++++++---------- test/export.yaml.t | 7 ++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/add-ons/export-yaml.pl b/scripts/add-ons/export-yaml.pl index 77d1632d4..ecf23ad5e 100755 --- a/scripts/add-ons/export-yaml.pl +++ b/scripts/add-ons/export-yaml.pl @@ -37,21 +37,18 @@ if ($@) exit 1; } -# Use the taskwarrior 2.0+ export command to filter and return JSON -my $command = join (' ', ("env PATH=$ENV{PATH} task export", @ARGV)); -if ($command =~ /No matches/) -{ - printf STDERR $command; - exit 1; -} - # Generate output. print "%YAML 1.1\n", "---\n"; -for my $task (split /,$/ms, qx{$command}) +while (my $json = <>) { - my $data = from_json ($task); + $json =~ s/^\[//; + $json =~ s/\]$//; + $json =~ s/,$//; + next if $json eq ''; + + my $data = from_json ($json); print " task:\n"; for my $key (sort keys %$data) diff --git a/test/export.yaml.t b/test/export.yaml.t index 9b6722473..34be1ecb7 100755 --- a/test/export.yaml.t +++ b/test/export.yaml.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 20; # Create the rc file. if (open my $fh, '>', 'export.rc') @@ -42,11 +42,8 @@ if (open my $fh, '>', 'export.rc') # Add two tasks, export, examine result. qx{../src/task rc:export.rc add priority:H project:A one}; qx{../src/task rc:export.rc add +tag1 +tag2 two}; -my $output = qx{env PATH=../src task rc:export.rc _version}; -like ($output, qr/^[a-z0-9]{7}$/, 'found task via env'); - -qx{env PATH=../src:$ENV{PATH} ../scripts/add-ons/export-yaml.pl rc:export.rc > ./export.txt}; +my $output = qx{../src/task rc:export.rc export | ../scripts/add-ons/export-yaml.pl > ./export.txt}; my @lines; if (open my $fh, '<', './export.txt') {