diff --git a/CMakeLists.txt b/CMakeLists.txt index 099c28c..2b24470 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,12 +57,16 @@ add_dependencies(bottles cog) add_library(launch SHARED ${src}/launch/launch.cpp ${src}/launch/commands.cpp ${src}/launch/shortcuts.cpp) +add_dependencies(launch cog) add_custom_target(cog ALL DEPENDS ${coggedfiles}) add_executable(cellar ${src}/cellar.cpp ${src}/commands.cpp ${src}/fs.cpp ${src}/version.cpp ${src}/output.cpp) target_link_libraries(cellar ${Boost_LIBRARIES} bottles launch) +add_dependencies(cellar cog) # effectively redundant but a couple of the bin's + # files are cogged, so this is mostly for people + # looking at CMakeLists.txt for hints install(TARGETS cellar bottles launch RUNTIME DESTINATION bin diff --git a/include/cellar.hpp b/include/cellar.hpp index 4704cd6..11c1cb3 100644 --- a/include/cellar.hpp +++ b/include/cellar.hpp @@ -4,12 +4,16 @@ #include #include +#include "bottles.hpp" + using namespace std; namespace cellar { extern void print_header(); extern void print_version(int,vector); + extern bottles::Bottle active_bottle; + extern bool verbose; } diff --git a/src/bottles/bottles.cpp b/src/bottles/bottles.cpp index 14ce2d3..5743797 100644 --- a/src/bottles/bottles.cpp +++ b/src/bottles/bottles.cpp @@ -30,6 +30,7 @@ Bottle::Bottle() { } Bottle::Bottle(string patharg) { + output::statement("loading bottle from " + patharg, true); config = json({}); path = patharg; diff --git a/src/bottles/config/cli_handler.cpp b/src/bottles/config/cli_handler.cpp index 4b2331b..20ddf3f 100644 --- a/src/bottles/config/cli_handler.cpp +++ b/src/bottles/config/cli_handler.cpp @@ -1,8 +1,8 @@ -#include #include #include #include "bottles.hpp" +#include "cellar.hpp" #include "internal/bottles.hpp" #include "output.hpp" @@ -26,11 +26,6 @@ void cellar::bottles::config_command(int argc, vector argv) { return; } - // TEMP - string homedir = getenv("HOME"); - Bottle active_bottle = Bottle(homedir + "/.wine"); - active_bottle.load_config(); - string key = argv[2]; string value = active_bottle.get_config(key); @@ -45,11 +40,6 @@ void cellar::bottles::config_command(int argc, vector argv) { return; } - // TEMP - string homedir = getenv("HOME"); - Bottle active_bottle = Bottle(homedir + "/.wine"); - active_bottle.load_config(); - string key = argv[2]; string newvalue = argv[3]; string oldvalue = active_bottle.get_config(key); diff --git a/src/cellar.cpp.cog b/src/cellar.cpp.cog index 0b9bd4b..82b2406 100644 --- a/src/cellar.cpp.cog +++ b/src/cellar.cpp.cog @@ -30,6 +30,8 @@ using json = nlohmann::json; bool cellar::verbose; +bottles::Bottle cellar::active_bottle; + void cellar::print_header() { output::statement("cellar - bottle management tool for WINE connoisseurs"); output::statement(version::short_version()); @@ -47,6 +49,9 @@ int main(int argc, char* argv[]) { const string versionstr = version::short_version(); TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false); + TCLAP::ValueArg bottlearg("b", "bottle", "Use a wine bottle other than the one at ~/.wine", false, "", "bottle"); + cmdparse.add(bottlearg); + TCLAP::SwitchArg verbosearg("v", "verbose", "Enables extra output"); cmdparse.add(verbosearg); @@ -61,19 +66,8 @@ int main(int argc, char* argv[]) { verbose = verbosearg.getValue(); // hardcoded because it's special - vector core_cmdnames; // mostly for verbose output for (auto item : commands::core_commands()) { commands::command_map[item.first] = item.second; - core_cmdnames.push_back(item.first); - } - - if (verbose) { // handling it here for efficiency - stringstream commandstring; - commandstring << "loading from core: "; - for (string item : core_cmdnames) { - commandstring << item << " "; - } - output::statement(commandstring.str(), true); } // as above, but cogged from src/modules.txt // BULLSHIT: trying to use str.format on this string causes bizarre compiler errors @@ -83,23 +77,57 @@ int main(int argc, char* argv[]) { with open("src/modules.txt") as modules: for module in modules: cog.out(""" - vector """ + module.strip() + """_cmdnames; for (auto item : commands::""" + module.strip() + """_commands()) { commands::command_map[item.first] = item.second; - """ + module.strip() + """_cmdnames.push_back(item.first); - } - - if (verbose) { - stringstream commandstring; - commandstring << "loading from """ + module.strip() + """: "; - for (string item : """ + module.strip() + """_cmdnames) { - commandstring << item << " "; - } - output::statement(commandstring.str(), true); } """, dedent=True, trimblanklines=True) ]]]*/ //[[[end]]] + + bool set_environment = true; + if (!bottlearg.isSet()) { // argument not passed + if (getenv("WINEPREFIX")) { + string env_wineprefix = getenv("WINEPREFIX"); + output::warning("cellar was designed to handle WINEPREFIX for you with the -b argument"); + output::warning("WINEPREFIX will be respected for consistency"); + active_bottle = bottles::Bottle(env_wineprefix); + } else { + string homepath = getenv("HOME"); + string fullbottlepath = homepath + "/.wine"; + active_bottle = bottles::Bottle(fullbottlepath); + } + + set_environment = false; + } else { + string bottlechoice = bottlearg.getValue(); + if (bottlechoice.substr(0,1) == "/" || bottlechoice.substr(0,1) == ".") { // absolute or relative path + active_bottle = bottles::Bottle(bottlechoice); + } else if (bottlechoice.substr(0,1) == "~") { // "absolute" path in home directory, not expanded by the shell for some reason (i've seen some shit) + // this is a naive replacement and will fail if the user tries something like ~nick/.wine + // i'm figuring at that point if you're doing that, you'll also recognize if your shell + // isn't actually expanding your path... + bottlechoice.replace(0,1,getenv("HOME")); + // or at least you'll think to use verbose mode to make sure it's loading the right directory + output::warning("your shell didn't expand your given path properly, doing a naive replacement", true); + active_bottle = bottles::Bottle(bottlechoice); + } else { + if (bottlechoice.substr(0,6) == ".wine.") { + output::statement("tip: cellar can add the \".wine.\" prefix automatically"); + bottlechoice.replace(0,6,""); + } + + string homepath = getenv("HOME"); + string fullbottlepath = homepath + "/.wine." + bottlechoice; + active_bottle = bottles::Bottle(fullbottlepath); + } + } + + active_bottle.load_config(); + + if (set_environment) { + output::statement("WINEPREFIX=" + active_bottle.path, true); + setenv("WINEPREFIX", active_bottle.path.c_str(), 1); + } string usercmd = command.getValue(); if (commands::command_map.count(usercmd) > 0) {