more updates
This commit is contained in:
parent
d2fab41864
commit
854ac405ad
3 changed files with 560 additions and 559 deletions
1017
include/argparse.hpp
1017
include/argparse.hpp
File diff suppressed because it is too large
Load diff
|
@ -10,11 +10,12 @@
|
|||
#else
|
||||
#include <pwd.h> // getpwuid, passwd
|
||||
#include <unistd.h> // getuid
|
||||
|
||||
#include "src/util/helpers.hpp"
|
||||
#endif
|
||||
|
||||
#include "src/util/defs.hpp"
|
||||
#include "src/util/error.hpp"
|
||||
#include "src/util/helpers.hpp"
|
||||
#include "src/util/logging.hpp"
|
||||
#include "src/util/types.hpp"
|
||||
|
||||
|
|
29
src/main.cpp
29
src/main.cpp
|
@ -23,31 +23,37 @@ using util::types::i32;
|
|||
|
||||
fn main(const i32 argc, char* argv[]) -> i32 {
|
||||
using namespace ftxui;
|
||||
using argparse::Argument, argparse::ArgumentParser;
|
||||
using os::SystemData;
|
||||
using util::types::Exception;
|
||||
|
||||
// TODO: don't wrap all of this in a try-catch
|
||||
try {
|
||||
#ifdef _WIN32
|
||||
winrt::init_apartment();
|
||||
#endif
|
||||
|
||||
argparse::ArgumentParser parser("draconis", "0.1.0");
|
||||
ArgumentParser parser("draconis", "0.1.0");
|
||||
|
||||
Argument& logLevel =
|
||||
parser
|
||||
.add_argument("--log-level")
|
||||
.help("Set the log level")
|
||||
.default_value("info")
|
||||
.choices("trace", "debug", "info", "warn", "error", "fatal");
|
||||
.default_value("info");
|
||||
|
||||
if (Result<Argument*> result = logLevel.choices("trace", "debug", "info", "warn", "error", "fatal"); !result) {
|
||||
error_log("Error setting choices: {}", result.error().message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
parser
|
||||
.add_argument("-V", "--verbose")
|
||||
.help("Enable verbose logging. Alias for --log-level=debug")
|
||||
.flag();
|
||||
|
||||
parser.parse_args(argc, argv);
|
||||
if (Result<> result = parser.parse_args(argc, argv); !result) {
|
||||
error_log("Error parsing arguments: {}", result.error().message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parser["--verbose"] == true || parser["-v"] == true)
|
||||
if (parser.get<bool>("--verbose").value_or(false) || parser.get<bool>("-v").value_or(false))
|
||||
info_log("Verbose logging enabled");
|
||||
|
||||
const Config& config = Config::getInstance();
|
||||
|
@ -64,13 +70,6 @@ fn main(const i32 argc, char* argv[]) -> i32 {
|
|||
#else
|
||||
std::cout << '\n';
|
||||
#endif
|
||||
} catch (const Exception& e) {
|
||||
error_log("Exception: {}", e.what());
|
||||
return 1;
|
||||
} catch (...) {
|
||||
error_log("Unknown exception");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue