support for being specific about your bottle, via -b flag
This commit is contained in:
parent
f20b0899a1
commit
06512f0503
@ -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
|
||||
|
@ -4,12 +4,16 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "bottles.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cellar {
|
||||
extern void print_header();
|
||||
extern void print_version(int,vector<string>);
|
||||
|
||||
extern bottles::Bottle active_bottle;
|
||||
|
||||
extern bool verbose;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ Bottle::Bottle() {
|
||||
}
|
||||
|
||||
Bottle::Bottle(string patharg) {
|
||||
output::statement("loading bottle from " + patharg, true);
|
||||
config = json({});
|
||||
path = patharg;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<string> 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<string> 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);
|
||||
|
@ -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<string> 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<string> 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<string> """ + 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user