diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 4078c598d..49158b7ba 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -52,6 +52,7 @@ CmdImport::CmdImport () int CmdImport::execute (std::string& output) { int rc = 0; + int count = 0; // Use the description as a file name. std::vector words = context.a3.extract_words (); @@ -164,14 +165,13 @@ int CmdImport::execute (std::string& output) task.validate (); - // TODO Verify uuid is unique, to prevent double-import. - std::cout << " " << task.get ("uuid") << " " << task.get ("description") << "\n"; context.tdb2.add (task); + ++count; } else throw std::string ("Not a JSON object: ") + *line; @@ -181,6 +181,8 @@ int CmdImport::execute (std::string& output) } context.tdb2.commit (); + + context.footnote (format (STRING_CMD_IMPORT_SUMMARY, count)); return rc; } diff --git a/src/en-US.h b/src/en-US.h index 75620ed8f..6276fa19e 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -309,6 +309,7 @@ #define STRING_CMD_DENO_FOUND "Found annotation '{1}' and deleted it." #define STRING_CMD_DENO_NOMATCH "Did not find any matching annotation to be deleted for '{1}'." #define STRING_CMD_IMPORT_USAGE "Imports JSON files." +#define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." diff --git a/test/import.t b/test/import.t new file mode 100755 index 000000000..a9a9ec933 --- /dev/null +++ b/test/import.t @@ -0,0 +1,112 @@ +#! /usr/bin/perl +################################################################################ +## taskwarrior - a command line task list manager. +## +## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 13; + +# Create the rc file. +if (open my $fh, '>', 'import.rc') +{ + print $fh "data.location=.\n"; + close $fh; + ok (-r 'import.rc', 'Created import.rc'); +} + +# Create import file. +if (open my $fh, '>', 'import.txt') +{ + print $fh <', 'import2.txt') +{ + print $fh <