From 1e49d8cdf198aaf4776654770022775eab79ca24 Mon Sep 17 00:00:00 2001 From: Kacper0510 Date: Fri, 10 May 2024 00:37:16 +0200 Subject: [PATCH] Version bump, add proper help message --- CMakeLists.txt | 2 +- resources/help.ansi | 23 ++++++++++++++++++++++- src/commands/info.hpp | 7 ++++++- src/files.hpp | 17 +++++++++++++++++ src/logging.hpp | 8 ++++---- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d7c225..5ea4044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22) -project(usos-rpc VERSION 0.2.0 HOMEPAGE_URL "github.com/Kacper0510/usos-rpc") +project(usos-rpc VERSION 1.0.0 HOMEPAGE_URL "github.com/Kacper0510/usos-rpc") set(usos-rpc_COPYRIGHT "(c) 2024 Kacper Wojciuch ") message("[usos-rpc] Starting CMake configuration") diff --git a/resources/help.ansi b/resources/help.ansi index 14d13fe..c8abb93 100644 --- a/resources/help.ansi +++ b/resources/help.ansi @@ -1 +1,22 @@ -USOS Discord Rich Presence {version} +USOS Discord Rich Presence {version} +Links your USOS timetable to Discord as an activity. + +Usage: {exe_name} [command] + +If no command has been specified, the program runs in "service mode", i.e. +does not ever stop unless terminated manually and continuously sends relevant +Rich Presence information to Discord, according to the configuration file. + +Available commands (can also be run with the preceding hyphens): + h, ?, help Shows this help message. + v, version Shows full version number and dependencies. + c, config Prints currently selected configuration directory +  path. See the next section for more information. + +Environment variables: + USOS_RPC_DIR Changes configuration directory to a custom location. +  Must be a valid path. By default, the home directory +  is selected on Linux and %AppData% on Windows. + NO_COLOR Disables ANSI color codes in the console output. + +Please report any bugs on GitHub: https://{github_url}/issues diff --git a/src/commands/info.hpp b/src/commands/info.hpp index a83c922..49f11a0 100644 --- a/src/commands/info.hpp +++ b/src/commands/info.hpp @@ -23,7 +23,12 @@ namespace usos_rpc::commands { /// @brief Prints the help message. void help() { - lprint(fmt::runtime(b::embed<"resources/help.ansi">().data()), fmt::arg("version", VERSION)); + lprint( + fmt::runtime(b::embed<"resources/help.ansi">().data()), + fmt::arg("version", VERSION), + fmt::arg("exe_name", get_executable_path().filename().string()), + fmt::arg("github_url", GITHUB_URL) + ); } /// @brief Prints the auto-selected config directory. diff --git a/src/files.hpp b/src/files.hpp index 2af8d24..6e6fa47 100644 --- a/src/files.hpp +++ b/src/files.hpp @@ -12,7 +12,9 @@ #ifdef _WIN32 #include + #include #else + #include #include #include #endif @@ -88,6 +90,21 @@ namespace usos_rpc { } } + /// @brief Retrieves current executable file path. + /// @see https://stackoverflow.com/a/55579815/23240713 + /// @return executable path + std::filesystem::path get_executable_path() { // clang-format off + #ifdef _WIN32 + wchar_t path[MAX_PATH] = { 0 }; + GetModuleFileNameW(nullptr, path, MAX_PATH); + return path; + #else + char result[PATH_MAX]; + ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); + return std::string(result, (count > 0) ? count : 0); + #endif + } // clang-format on + /// @brief Reads file contents. /// @param path file path to read /// @return file contents diff --git a/src/logging.hpp b/src/logging.hpp index a71dd92..d88fd7f 100644 --- a/src/logging.hpp +++ b/src/logging.hpp @@ -72,16 +72,16 @@ namespace usos_rpc { namespace colors { /// @brief Exception warnings formatting style. - constexpr fmt::text_style WARNING = fmt::fg(fmt::terminal_color::yellow); + constexpr fmt::text_style WARNING = fmt::fg(fmt::terminal_color::bright_yellow); /// @brief Fatal errors formatting style. - constexpr fmt::text_style FATAL_ERROR = fmt::fg(fmt::terminal_color::red); + constexpr fmt::text_style FATAL_ERROR = fmt::fg(fmt::terminal_color::bright_red); /// @brief Formatting style for messages indicating some kind of a success. - constexpr fmt::text_style SUCCESS = fmt::fg(fmt::terminal_color::green); + constexpr fmt::text_style SUCCESS = fmt::fg(fmt::terminal_color::bright_green); /// @brief Formatting style for other messages that should stand out. - constexpr fmt::text_style OTHER = fmt::fg(fmt::terminal_color::blue); + constexpr fmt::text_style OTHER = fmt::fg(fmt::terminal_color::bright_cyan); } }