From 8e75e7bfbf14566c22140fb3e7822b05feef57b4 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 22 May 2019 09:43:58 +0200 Subject: [PATCH] Added option to not archive page. --- remwharead.1.adoc | 3 +++ src/main.cpp | 7 ++++++- src/parse_options.cpp | 22 ++++++++++------------ src/parse_options.hpp | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/remwharead.1.adoc b/remwharead.1.adoc index 92e5b44..a2ac62c 100644 --- a/remwharead.1.adoc +++ b/remwharead.1.adoc @@ -52,6 +52,9 @@ Search in tags. Format: _tag1 AND tag2 OR tag3_. See _SEARCH EXPRESSIONS_. *--search-all* _expression_:: Search in tags, title, description and full text. +*-N*, *--no-archive*:: +Do not archive URI. + *-h*, *--help*:: Show help message. diff --git a/src/main.cpp b/src/main.cpp index 7465bb7..dcd92ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,12 @@ int main(const int argc, const char *argv[]) cerr << "Error: Could not fetch page.\n"; return 4; } - db.store({opts.uri, uri.archive(), system_clock::now(), opts.tags, + string archive_uri; + if (opts.archive) + { + archive_uri = uri.archive(); + } + db.store({opts.uri, archive_uri, system_clock::now(), opts.tags, page.title, page.description, page.fulltext}); } diff --git a/src/parse_options.cpp b/src/parse_options.cpp index eab570d..86bb9f6 100644 --- a/src/parse_options.cpp +++ b/src/parse_options.cpp @@ -35,10 +35,7 @@ const options parse_options(const int argc, const char *argv[]) { string tags; string format; - string file; string span; - string search_tags; - string search_all; options opts; try @@ -49,18 +46,20 @@ const options parse_options(const int argc, const char *argv[]) op.add> ("e", "export", "Export to format.", "", &format); op.add> - ("f", "file", "Save output to file.", "", &file); + ("f", "file", "Save output to file.", "", &opts.file); op.add> ("S", "span", "Only export entries between YYYY-MM-DD,YYYY-MM-DD.", "", &span); op.add> ("s", "search-tags", "Search in tags. Format: tag1 AND tag2 OR tag3.", - "", &search_tags); + "", &opts.search_tags); op.add> ("", "search-all", "Search in tags, title, description and full text.", - "", &search_all); + "", &opts.search_all); + auto option_noarchive = op.add + ("N", "no-archive", "Do not archive URI."); auto option_help = op.add ("h", "help", "Show this help message."); auto option_version = op.add @@ -88,6 +87,11 @@ const options parse_options(const int argc, const char *argv[]) return options(0); } + if (option_noarchive->is_set()) + { + opts.archive = false; + } + if (!tags.empty()) { size_t pos_end = 0; @@ -119,8 +123,6 @@ const options parse_options(const int argc, const char *argv[]) } } - opts.file = file; - if (!span.empty()) { size_t pos = span.find(','); @@ -140,10 +142,6 @@ const options parse_options(const int argc, const char *argv[]) } } - opts.search_tags = search_tags; - - opts.search_all = search_all; - if (op.non_option_args().size() > 0) { opts.uri = op.non_option_args().front(); diff --git a/src/parse_options.hpp b/src/parse_options.hpp index f510c58..653ed35 100644 --- a/src/parse_options.hpp +++ b/src/parse_options.hpp @@ -41,6 +41,7 @@ typedef struct options string uri; string search_tags; string search_all; + bool archive = true; uint8_t status_code = 0; options();