This commit is contained in:
Mars 2025-05-06 01:12:37 -04:00
parent 816619a162
commit d2fab41864
4 changed files with 298 additions and 206 deletions

View file

@ -1,3 +1,4 @@
#define NOMINMAX
#include "weather.hpp"
#include <chrono> // std::chrono::{duration, operator-}

View file

@ -24,55 +24,53 @@ using util::types::i32;
fn main(const i32 argc, char* argv[]) -> i32 {
using namespace ftxui;
using os::SystemData;
using util::types::Exception;
#ifdef _WIN32
winrt::init_apartment();
#endif
argparse::ArgumentParser parser("draconis", "0.1.0");
parser
.add_argument("--log-level")
.help("Set the log level")
.default_value("info")
.choices("trace", "debug", "info", "warn", "error", "fatal");
parser
.add_argument("-V", "--verbose")
.help("Enable verbose logging. Alias for --log-level=debug")
.flag();
// TODO: don't wrap all of this in a try-catch
try {
parser.parse_args(argc, argv);
} catch (const util::types::Exception& err) {
#ifdef __cpp_lib_print
std::println(stderr, "{}", err.what());
#else
std::cerr << err.what() << '\n';
#ifdef _WIN32
winrt::init_apartment();
#endif
std::cerr << parser;
argparse::ArgumentParser parser("draconis", "0.1.0");
parser
.add_argument("--log-level")
.help("Set the log level")
.default_value("info")
.choices("trace", "debug", "info", "warn", "error", "fatal");
parser
.add_argument("-V", "--verbose")
.help("Enable verbose logging. Alias for --log-level=debug")
.flag();
parser.parse_args(argc, argv);
if (parser["--verbose"] == true || parser["-v"] == true)
info_log("Verbose logging enabled");
const Config& config = Config::getInstance();
const SystemData data = SystemData(config);
Element document = ui::CreateUI(config, data);
Screen screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
#ifdef __cpp_lib_print
std::println();
#else
std::cout << '\n';
#endif
} catch (const Exception& e) {
error_log("Exception: {}", e.what());
return 1;
} catch (...) {
error_log("Unknown exception");
return 1;
}
if (parser["--verbose"] == true || parser["-v"] == true)
info_log("Verbose logging enabled");
const Config& config = Config::getInstance();
const SystemData data = SystemData(config);
Element document = ui::CreateUI(config, data);
Screen screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
#ifdef __cpp_lib_print
std::println();
#else
std::cout << '\n';
#endif
return 0;
}

View file

@ -6,6 +6,7 @@
#include <system_error> // std::error_code
#ifdef _WIN32
#include <guiddef.h> // GUID
#include <winerror.h> // error values
#include <winrt/base.h> // winrt::hresult_error
#endif
@ -77,14 +78,14 @@ namespace util {
}
#ifdef _WIN32
explicit DracError(const winrt::hresult_error& e)
: message(winrt::to_string(e.message())) {
explicit DracError(const winrt::hresult_error& err)
: message(winrt::to_string(err.message())) {
using namespace matchit;
using enum DracErrorCode;
fn fromWin32 = [](const types::u32 x) -> HRESULT { return HRESULT_FROM_WIN32(x); };
fn fromWin32 = [](const types::u32 win32) -> HRESULT { return HRESULT_FROM_WIN32(win32); };
code = match(e.code())(
code = match(err.code())(
is | or_(E_ACCESSDENIED, fromWin32(ERROR_ACCESS_DENIED)) = PermissionDenied,
is | fromWin32(ERROR_FILE_NOT_FOUND) = NotFound,
is | fromWin32(ERROR_PATH_NOT_FOUND) = NotFound,