From bf135b28b624deaf21eac7ec7b55e5c276f33683 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 13 May 2019 02:33:43 +0200 Subject: [PATCH] Added url to options. --- src/parse_options.cpp | 12 ++++++++++++ src/parse_options.hpp | 4 +++- tests/test_parse_options.cpp | 14 +++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/parse_options.cpp b/src/parse_options.cpp index 7df6c7a..6e7f048 100644 --- a/src/parse_options.cpp +++ b/src/parse_options.cpp @@ -115,6 +115,7 @@ const options parse_options(const int argc, const char *argv[]) } else { + opts.format = export_format::undefined; cerr << "Error: Export format must be csv or asciidoc.\n"; return options(1); } @@ -140,6 +141,17 @@ const options parse_options(const int argc, const char *argv[]) return options(1); } } + + if (op.non_option_args().size() > 0) + { + opts.url = op.non_option_args().front(); + } + + if (opts.url == "" && opts.format == export_format::undefined) + { + cerr << "Error: You have to specify either URL or --export.\n"; + return options(1); + } } catch (const std::exception &e) { diff --git a/src/parse_options.hpp b/src/parse_options.hpp index 17ee07a..b00e2f1 100644 --- a/src/parse_options.hpp +++ b/src/parse_options.hpp @@ -31,6 +31,7 @@ using std::uint8_t; enum class export_format { + undefined, csv, asciidoc }; @@ -38,9 +39,10 @@ enum class export_format typedef struct options { vector tags; - export_format format = {}; + export_format format = export_format::undefined; string file; array span; + string url; uint8_t status_code = 0; options(); diff --git a/tests/test_parse_options.cpp b/tests/test_parse_options.cpp index fd2f510..b2dc129 100644 --- a/tests/test_parse_options.cpp +++ b/tests/test_parse_options.cpp @@ -59,6 +59,7 @@ SCENARIO ("The option parser works correctly") { bool exception = false; options opts; + const string url = "https://example.com/article.html"; WHEN ("The options are --help --file test") { @@ -106,13 +107,13 @@ SCENARIO ("The option parser works correctly") } } - WHEN ("The options are -t 💩") + WHEN ("The options are -t 💩 " + url) { try { const char *argv[] - = { "remwharead", "-t", "💩" }; - opts = parse_options(3, argv); + = { "remwharead", "-t", "💩", url.c_str() }; + opts = parse_options(4, argv); } catch (const std::exception &e) { @@ -126,6 +127,7 @@ SCENARIO ("The option parser works correctly") REQUIRE_FALSE(exception); REQUIRE(opts.status_code == 0); REQUIRE(opts.tags == vector{ "💩" }); + REQUIRE(opts.url == url); } } @@ -144,9 +146,10 @@ SCENARIO ("The option parser works correctly") { "remwharead", "-t", - tags.c_str() + tags.c_str(), + url.c_str() }; - opts = parse_options(3, argv); + opts = parse_options(4, argv); } catch (const std::exception &e) { @@ -160,6 +163,7 @@ SCENARIO ("The option parser works correctly") REQUIRE_FALSE(exception); REQUIRE(opts.status_code == 0); REQUIRE(opts.tags == vector{ "tag1", longstring, "tag3" }); + REQUIRE(opts.url == url); } } }