Skip to content

Commit

Permalink
Version bump, add proper help message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper0510 committed May 9, 2024
1 parent bb0a983 commit 1e49d8c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <wkacper@spoko.pl>")
message("[usos-rpc] Starting CMake configuration")

Expand Down
23 changes: 22 additions & 1 deletion resources/help.ansi
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/commands/info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

#ifdef _WIN32
#include <shlobj.h>
#include <windows.h>
#else
#include <limits.h>
#include <pwd.h>
#include <unistd.h>
#endif
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 1e49d8c

Please sign in to comment.