From 965c4614b2fae658e210b78c10c59de6688fdcf3 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 28 Aug 2023 16:53:23 +0200 Subject: [PATCH] Add help, verbose and quiet args --- src/helpers/Log.hpp | 10 ++++++++++ src/main.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/helpers/Log.hpp b/src/helpers/Log.hpp index 7aa0c25..97783c4 100644 --- a/src/helpers/Log.hpp +++ b/src/helpers/Log.hpp @@ -25,8 +25,18 @@ enum eLogLevel #define ASSERT(expr) RASSERT(expr, "?") namespace Debug { + inline bool quiet = false; + inline bool verbose = false; + template void log(eLogLevel level, const std::string& fmt, Args&&... args) { + + if (!verbose && level == TRACE) + return; + + if (quiet) + return; + std::cout << '['; switch (level) { diff --git a/src/main.cpp b/src/main.cpp index 14321ac..d7a4482 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,10 +3,38 @@ #include "helpers/Log.hpp" #include "core/PortalManager.hpp" +void printHelp() { + std::cout << R"#(| xdg-desktop-portal-hyprland +| -------------------------------------- +| -v (--verbose) > enable trace logging +| -q (--quiet) > disable logging +| -h (--help) > print this menu +)#"; +} + int main(int argc, char** argv, char** envp) { + g_pPortalManager = std::make_unique(); + + for (int i = 1; i < argc; ++i) { + std::string arg = argv[i]; + + if (arg == "--verbose" || arg == "-v") + Debug::verbose = true; + + else if (arg == "--quiet" || arg == "-q") + Debug::quiet = true; + + else if (arg == "--help" || arg == "-h") { + printHelp(); + return 0; + } else { + printHelp(); + return 1; + } + } + Debug::log(LOG, "Initializing xdph..."); - g_pPortalManager = std::make_unique(); g_pPortalManager->init(); return 0;