From 71bce0c87da9f44c2307977ff9aca5d7cdc656aa Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 21 Jul 2019 16:37:36 +0200 Subject: [PATCH] =?UTF-8?q?Added=20=E2=80=9Csimple=E2=80=9D=20export.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 14 ++++++++++++++ src/parse_options.cpp | 12 ++++++++---- src/simple.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/simple.hpp | 33 +++++++++++++++++++++++++++++++++ src/types.hpp | 3 ++- 5 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 src/simple.cpp create mode 100644 src/simple.hpp diff --git a/src/main.cpp b/src/main.cpp index 1d1f5d6..c22d3f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include "csv.hpp" #include "adoc.hpp" #include "bookmarks.hpp" +#include "simple.hpp" #include "search.hpp" using std::cout; @@ -135,6 +136,19 @@ int main(const int argc, const char *argv[]) } break; } + case export_format::simple: + { + if (file.is_open()) + { + Export::Simple(entries, file).print(); + file.close(); + } + else + { + Export::Simple(entries).print(); + } + break; + } default: { break; diff --git a/src/parse_options.cpp b/src/parse_options.cpp index 26fcb1f..7cc7602 100644 --- a/src/parse_options.cpp +++ b/src/parse_options.cpp @@ -43,8 +43,8 @@ const options parse_options(const int argc, const char *argv[]) popl::OptionParser op("Available options"); op.add> ("t", "tags", "Add tags to URI, delimited by commas.", "", &tags); - op.add> - ("e", "export", "Export to format.", "", &format); + auto option_export = op.add> + ("e", "export", "Export to format.", "simple", &format); op.add> ("f", "file", "Save output to file.", "", &opts.file); op.add> @@ -113,7 +113,7 @@ const options parse_options(const int argc, const char *argv[]) } } - if (!format.empty()) + if (option_export->is_set()) { if (format == "csv") { @@ -127,11 +127,15 @@ const options parse_options(const int argc, const char *argv[]) { opts.format = export_format::bookmarks; } + else if (format == "simple") + { + opts.format = export_format::simple; + } else { opts.format = export_format::undefined; cerr << "Error: Export format must be " - << "csv, asciidoc or bookmarks.\n"; + << "csv, asciidoc, bookmarks or simple.\n"; return options(1); } } diff --git a/src/simple.cpp b/src/simple.cpp new file mode 100644 index 0000000..5a7c9ae --- /dev/null +++ b/src/simple.cpp @@ -0,0 +1,38 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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, version 3. + * + * 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, see . + */ + +#include +#include "sqlite.hpp" +#include "time.hpp" +#include "simple.hpp" + +using std::string; + +void Export::Simple::print() const +{ + for (const Database::entry & entry : _entries) + { + const string timestring = timepoint_to_string(entry.datetime); + _out << timestring.substr(0, timestring.find('T')) << ": "; + if (!entry.title.empty()) + { + _out << entry.title << '\n'; + _out << " "; + } + + _out << "<" << entry.uri << ">\n"; + } +} diff --git a/src/simple.hpp b/src/simple.hpp new file mode 100644 index 0000000..1638d9a --- /dev/null +++ b/src/simple.hpp @@ -0,0 +1,33 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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, version 3. + * + * 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, see . + */ + +#ifndef REMWHAREAD_SIMPLE_HPP +#define REMWHAREAD_SIMPLE_HPP + +#include "export.hpp" + +namespace Export +{ + //! Export as simple list. + class Simple : protected ExportBase + { + public: + using ExportBase::ExportBase; + virtual void print() const override; + }; +} + +#endif // REMWHAREAD_SIMPLE_HPP diff --git a/src/types.hpp b/src/types.hpp index be23767..f1940e6 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -22,7 +22,8 @@ enum class export_format undefined, csv, asciidoc, - bookmarks + bookmarks, + simple }; #endif // REMWHAREAD_TYPES_HPP