feat: add default config fallback
All checks were successful
CI / build (amd64, usbmakroboard-amd64, linux_amd64) (pull_request) Successful in 1m9s
CI / build (arm64, usbmakroboard-arm64, linux_arm64) (pull_request) Successful in 4m5s

This commit is contained in:
2025-12-27 13:17:00 +01:00
parent 3052bb199f
commit 57b7dc8412

View File

@@ -7,6 +7,7 @@
#include <fcntl.h>
#include <linux/input.h>
#include <iostream>
#include <cstdlib>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_sinks.h>
#include <yaml-cpp/yaml.h>
@@ -57,7 +58,7 @@ std::pair<int, int> mapKeyEventToRowColumn(int keyEventNumber, const std::unorde
std::string getConfigPathFromCliArguments(int argc, char *argv[])
{
std::string configPath = "config.yaml";
std::string configPath;
int opt;
while ((opt = getopt(argc, argv, "c:")) != -1)
{
@@ -71,6 +72,18 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
if (configPath.empty()) {
const char *home = std::getenv("HOME");
if (home != nullptr) {
configPath = std::string(home) + "/.config/usbMakroBoard.yaml";
}
else {
std::cerr << "HOME environment variable is not set. Exiting.\n";
exit(EXIT_FAILURE);
}
}
return configPath;
}