From 63005f5fc81e9b641f07eadb5f07bc7c532d40c7 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 20:50:44 +1300 Subject: feat: Added new command line option --config (-c) The new options allows you to specify the location of the config file in the arguments to the program. --- src/main.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 3e01b4d..291151f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -36,8 +35,7 @@ #include "config.h" #include "util.h" #include "ewmh.h" -//TODO: FIX THIS -#include +#include "error.h" using std::cout; using std::string; @@ -1030,13 +1028,15 @@ int main(int argc, char** argv) { int versionFlag = 0; bool immediateExit = false; + string configLocation = ""; while(1) { static option long_options[] = {{"version", no_argument, &versionFlag, 1}, + {"config", required_argument, NULL, 'c'}, {0, 0, 0, 0}}; int optionIndex; - char c = getopt_long(argc, argv, "v", long_options, &optionIndex); + char c = getopt_long(argc, argv, "c:v", long_options, &optionIndex); if(c == -1) break; @@ -1048,8 +1048,12 @@ int main(int argc, char** argv) break; //Option had arg break; + case 'c': + configLocation = string(optarg); + break; case 'v': versionFlag = 1; + break; case '?': //Error?? break; @@ -1124,16 +1128,19 @@ int main(int argc, char** argv) std::vector cfgErr; cout << "Registered commands" << endl; - - char* confDir = getenv("XDG_CONFIG_HOME"); - if(confDir != NULL) - { - cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); - } + + if(configLocation != "") + cfgErr = cfg.loadFromFile(configLocation); else { - string home = getenv("HOME"); - cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + char* confDir = getenv("XDG_CONFIG_HOME"); + if(confDir != NULL) + cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); + else + { + string home = getenv("HOME"); + cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + } } cout << "Done config" << endl; @@ -1234,7 +1241,6 @@ int main(int argc, char** argv) } if(ready == -1) { - cout << "E" << endl; log("ERROR"); } } -- cgit v1.2.3