Replaced exit with return.
This commit is contained in:
parent
5cd5740fd0
commit
17522d6757
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "sqlite.hpp"
|
||||||
#include "parse_options.hpp"
|
#include "parse_options.hpp"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
@ -23,9 +24,13 @@ using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(const int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
options opts = parse_options(argc, argv);
|
options opts = parse_options(argc, argv);
|
||||||
|
if (opts.status_code != 0)
|
||||||
|
{
|
||||||
|
return opts.status_code;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,13 @@
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::exit;
|
|
||||||
|
options::options()
|
||||||
|
{}
|
||||||
|
|
||||||
|
options::options(const uint8_t &status)
|
||||||
|
: status_code(status)
|
||||||
|
{}
|
||||||
|
|
||||||
const system_clock::time_point string_to_timepoint(const string &strtime)
|
const system_clock::time_point string_to_timepoint(const string &strtime)
|
||||||
{
|
{
|
||||||
|
@ -38,7 +44,7 @@ const system_clock::time_point string_to_timepoint(const string &strtime)
|
||||||
return system_clock::from_time_t(time);
|
return system_clock::from_time_t(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
const options parse_options(int argc, char *argv[])
|
const options parse_options(const int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
string tags;
|
string tags;
|
||||||
string format;
|
string format;
|
||||||
|
@ -68,7 +74,7 @@ const options parse_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
cout << "Usage: " << argv[0] << " [-t tags] URL\n";
|
cout << "Usage: " << argv[0] << " [-t tags] URL\n";
|
||||||
cout << op;
|
cout << op;
|
||||||
exit(0);
|
return options(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option_version->is_set())
|
if (option_version->is_set())
|
||||||
|
@ -79,7 +85,7 @@ const options parse_options(int argc, char *argv[])
|
||||||
"<https://www.gnu.org/licenses/gpl-3.0.html>.\n"
|
"<https://www.gnu.org/licenses/gpl-3.0.html>.\n"
|
||||||
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
|
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
|
||||||
"and you are welcome to redistribute it under certain conditions.\n";
|
"and you are welcome to redistribute it under certain conditions.\n";
|
||||||
exit(0);
|
return options(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tags.empty())
|
if (!tags.empty())
|
||||||
|
@ -108,7 +114,7 @@ const options parse_options(int argc, char *argv[])
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "Error: Export format must be csv or asciidoc.\n";
|
cerr << "Error: Export format must be csv or asciidoc.\n";
|
||||||
exit(1);
|
return options(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,14 +135,14 @@ const options parse_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
cerr << "Error: Time span must be in format: "
|
cerr << "Error: Time span must be in format: "
|
||||||
"YYYY-MM-DD,YYYY-MM-DD\n";
|
"YYYY-MM-DD,YYYY-MM-DD\n";
|
||||||
exit(1);
|
return options(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
cerr << "Error: " << e.what() << endl;
|
cerr << "Error: " << e.what() << endl;
|
||||||
exit(1);
|
return options(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdlib>
|
#include <cstdint>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
@ -41,12 +41,16 @@ typedef struct options
|
||||||
export_format format = {};
|
export_format format = {};
|
||||||
string file;
|
string file;
|
||||||
array<system_clock::time_point, 2> span;
|
array<system_clock::time_point, 2> span;
|
||||||
|
uint8_t status_code = 0;
|
||||||
|
|
||||||
|
options();
|
||||||
|
explicit options(const uint8_t &status);
|
||||||
} options;
|
} options;
|
||||||
|
|
||||||
// Convert ISO 8601 time-string to time_point.
|
// Convert ISO 8601 time-string to time_point.
|
||||||
const system_clock::time_point string_to_timepoint(const string &strtime);
|
const system_clock::time_point string_to_timepoint(const string &strtime);
|
||||||
|
|
||||||
// Parse command-line options.
|
// Parse command-line options.
|
||||||
const options parse_options(int argc, char *argv[]);
|
const options parse_options(const int argc, const char *argv[]);
|
||||||
|
|
||||||
#endif // REMWHAREAD_PARSE_OPTIONS_HPP
|
#endif // REMWHAREAD_PARSE_OPTIONS_HPP
|
||||||
|
|
Loading…
Reference in New Issue