Added url to options.

This commit is contained in:
tastytea 2019-05-13 02:33:43 +02:00
parent 6c7a4d6685
commit bf135b28b6
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 24 additions and 6 deletions

View File

@ -115,6 +115,7 @@ const options parse_options(const int argc, const char *argv[])
} }
else else
{ {
opts.format = export_format::undefined;
cerr << "Error: Export format must be csv or asciidoc.\n"; cerr << "Error: Export format must be csv or asciidoc.\n";
return options(1); return options(1);
} }
@ -140,6 +141,17 @@ const options parse_options(const int argc, const char *argv[])
return options(1); 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) catch (const std::exception &e)
{ {

View File

@ -31,6 +31,7 @@ using std::uint8_t;
enum class export_format enum class export_format
{ {
undefined,
csv, csv,
asciidoc asciidoc
}; };
@ -38,9 +39,10 @@ enum class export_format
typedef struct options typedef struct options
{ {
vector<string> tags; vector<string> tags;
export_format format = {}; export_format format = export_format::undefined;
string file; string file;
array<system_clock::time_point, 2> span; array<system_clock::time_point, 2> span;
string url;
uint8_t status_code = 0; uint8_t status_code = 0;
options(); options();

View File

@ -59,6 +59,7 @@ SCENARIO ("The option parser works correctly")
{ {
bool exception = false; bool exception = false;
options opts; options opts;
const string url = "https://example.com/article.html";
WHEN ("The options are --help --file test") 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 try
{ {
const char *argv[] const char *argv[]
= { "remwharead", "-t", "💩" }; = { "remwharead", "-t", "💩", url.c_str() };
opts = parse_options(3, argv); opts = parse_options(4, argv);
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
@ -126,6 +127,7 @@ SCENARIO ("The option parser works correctly")
REQUIRE_FALSE(exception); REQUIRE_FALSE(exception);
REQUIRE(opts.status_code == 0); REQUIRE(opts.status_code == 0);
REQUIRE(opts.tags == vector<string>{ "💩" }); REQUIRE(opts.tags == vector<string>{ "💩" });
REQUIRE(opts.url == url);
} }
} }
@ -144,9 +146,10 @@ SCENARIO ("The option parser works correctly")
{ {
"remwharead", "remwharead",
"-t", "-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) catch (const std::exception &e)
{ {
@ -160,6 +163,7 @@ SCENARIO ("The option parser works correctly")
REQUIRE_FALSE(exception); REQUIRE_FALSE(exception);
REQUIRE(opts.status_code == 0); REQUIRE(opts.status_code == 0);
REQUIRE(opts.tags == vector<string>{ "tag1", longstring, "tag3" }); REQUIRE(opts.tags == vector<string>{ "tag1", longstring, "tag3" });
REQUIRE(opts.url == url);
} }
} }
} }