Replaced exit with return.

This commit is contained in:
tastytea 2019-05-12 20:19:00 +02:00
parent 5cd5740fd0
commit 17522d6757
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 25 additions and 10 deletions

View File

@ -16,6 +16,7 @@
#include <iostream>
#include <string>
#include "sqlite.hpp"
#include "parse_options.hpp"
using std::cout;
@ -23,9 +24,13 @@ using std::cerr;
using std::endl;
using std::string;
int main(int argc, char *argv[])
int main(const int argc, const char *argv[])
{
options opts = parse_options(argc, argv);
if (opts.status_code != 0)
{
return opts.status_code;
}
return 0;
}

View File

@ -26,7 +26,13 @@
using std::cout;
using std::cerr;
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)
{
@ -38,7 +44,7 @@ const system_clock::time_point string_to_timepoint(const string &strtime)
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 format;
@ -68,7 +74,7 @@ const options parse_options(int argc, char *argv[])
{
cout << "Usage: " << argv[0] << " [-t tags] URL\n";
cout << op;
exit(0);
return options(0);
}
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"
"This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions.\n";
exit(0);
return options(0);
}
if (!tags.empty())
@ -108,7 +114,7 @@ const options parse_options(int argc, char *argv[])
else
{
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: "
"YYYY-MM-DD,YYYY-MM-DD\n";
exit(1);
return options(1);
}
}
}
catch (const std::exception &e)
{
cerr << "Error: " << e.what() << endl;
exit(1);
return options(1);
}
return opts;

View File

@ -21,7 +21,7 @@
#include <vector>
#include <array>
#include <chrono>
#include <cstdlib>
#include <cstdint>
using std::string;
using std::vector;
@ -41,12 +41,16 @@ typedef struct options
export_format format = {};
string file;
array<system_clock::time_point, 2> span;
uint8_t status_code = 0;
options();
explicit options(const uint8_t &status);
} options;
// Convert ISO 8601 time-string to time_point.
const system_clock::time_point string_to_timepoint(const string &strtime);
// 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