diff --git a/include/export/link.hpp b/include/export/link.hpp new file mode 100644 index 0000000..71e0140 --- /dev/null +++ b/include/export/link.hpp @@ -0,0 +1,39 @@ +/* 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_EXPORT_LINK_HPP +#define REMWHAREAD_EXPORT_LINK_HPP + +#include "export.hpp" + +namespace remwharead::Export +{ +/*! + * @brief Export as list of hyperlinks. + * + * @since 0.9.0 + * + * @headerfile link.hpp remwharead/export/link.hpp + */ +class Link : protected ExportBase +{ +public: + using ExportBase::ExportBase; + void print() const override; +}; +} // namespace remwharead::Export + +#endif // REMWHAREAD_EXPORT_LINK_HPP diff --git a/include/types.hpp b/include/types.hpp index 2b15b0e..6f01510 100644 --- a/include/types.hpp +++ b/include/types.hpp @@ -36,7 +36,8 @@ enum class export_format bookmarks, simple, json, - rss + rss, + link }; } // namespace remwharead diff --git a/man/remwharead.1.adoc b/man/remwharead.1.adoc index 46c7b04..ccffe66 100644 --- a/man/remwharead.1.adoc +++ b/man/remwharead.1.adoc @@ -2,7 +2,7 @@ :doctype: manpage :Author: tastytea :Email: tastytea@tastytea.de -:Date: 2019-10-15 +:Date: 2019-11-27 :Revision: 0.0.0 :man source: remwharead :man manual: General Commands Manual @@ -24,7 +24,7 @@ remwharead - Saves URIs of things you want to remember in a database the full text of the page and optional tags. The database can be filtered by time, tags and full text and exported to CSV, -AsciiDoc, a bookmarks file, JSON or RSS. +AsciiDoc, a bookmarks file, JSON, RSS or a list of hyperlinks. Archiving is done using the Wayback machine from the https://archive.org/[Internet Archive]. @@ -36,7 +36,7 @@ Add tags to _URI_, delimited by commas. *-e*=_format_, *--export*=_format_:: Export to _format_. Possible values are _csv_, _asciidoc_, _bookmarks_, -_simple_, _json_ or _rss_. See _FORMATS_. +_simple_, _json_, _rss_ or _link_. See _FORMATS_. *-f*=_file_, *--file*=_file_:: Save output to _file_. Default is stdout. @@ -149,6 +149,10 @@ Export as http://www.rssboard.org/rss-specification[RSS] feed. Because the URL of the feed is unknown to *remwharead*, the generated feed is slightly out of specification (the element _link_ in _channel_ is empty). +=== link + +Export as a plain list of links, separated by newlines. + == SEARCH EXPRESSIONS A search expression is either a single term, or several terms separated by _AND_ diff --git a/src/cli/main.cpp b/src/cli/main.cpp index d95f40b..1206732 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -19,6 +19,7 @@ #include "export/bookmarks.hpp" #include "export/csv.hpp" #include "export/json.hpp" +#include "export/link.hpp" #include "export/rss.hpp" #include "export/simple.hpp" #include "search.hpp" @@ -214,6 +215,19 @@ int App::main(const std::vector &args) } break; } + case export_format::link: + { + if (file.is_open()) + { + Export::Link(entries, file).print(); + file.close(); + } + else + { + Export::Link(entries).print(); + } + break; + } default: { break; diff --git a/src/cli/parse_options.cpp b/src/cli/parse_options.cpp index 5157294..735ed44 100644 --- a/src/cli/parse_options.cpp +++ b/src/cli/parse_options.cpp @@ -146,6 +146,10 @@ void App::handle_options(const std::string &name, const std::string &value) { _format = export_format::rss; } + else if (value == "link") + { + _format = export_format::link; + } else { cerr << "Error: Unknown format.\n"; diff --git a/src/lib/export/link.cpp b/src/lib/export/link.cpp new file mode 100644 index 0000000..fcb9473 --- /dev/null +++ b/src/lib/export/link.cpp @@ -0,0 +1,32 @@ +/* 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 "export/link.hpp" +#include "sqlite.hpp" +#include + +namespace remwharead +{ +using std::string; + +void Export::Link::print() const +{ + for (const Database::entry & entry : _entries) + { + _out << entry.uri << '\n'; + } +} +} // namespace remwharead diff --git a/tests/test_link.cpp b/tests/test_link.cpp new file mode 100644 index 0000000..08a9be7 --- /dev/null +++ b/tests/test_link.cpp @@ -0,0 +1,60 @@ +/* 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 +#include +#include +#include "sqlite.hpp" +#include "export/link.hpp" + +using namespace remwharead; +using std::string; + +SCENARIO ("The Link export works correctly") +{ + bool exception = false; + bool link_ok = true; + + GIVEN ("One database entry") + { + Database::entry entry; + entry.uri = "https://example.com/page.html"; + + try + { + std::ostringstream output; + Export::Link({ entry }, output).print(); + const string link = output.str(); + + if (link != (entry.uri + '\n')) + { + link_ok = false; + } + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Output looks okay") + { + REQUIRE_FALSE(exception); + REQUIRE(link_ok); + } + } +}