config command can get values now

This commit is contained in:
Nicholas O'Connor 2017-03-24 18:45:50 -07:00
parent 22cffca2d8
commit c877663932
2 changed files with 40 additions and 1 deletions

View File

@ -1,3 +1,4 @@
#include <cstdlib>
#include <string>
#include <vector>
@ -18,5 +19,30 @@ void cellar::bottles::config_command(int argc, vector<string> argv) {
}
string command = argv[1];
output::statement(command);
// BULLSHIT: switch can't be used for strings, according to gcc
if (command == "get") {
if (argc < 3) {
output::error("usage: " + argv[0] + " get <key>");
return;
}
// TEMP
string homedir = getenv("HOME");
Bottle active_bottle = Bottle(homedir + "/.wine");
active_bottle.load_config();
string value = active_bottle.get_config(argv[2]);
if (value != "") {
output::statement(argv[2] + ": " + value);
} else {
output::error(argv[2] + " is not defined");
}
} else if (command == "set") {
output::statement("usage: " + argv[0] + " set <key> <value>");
} else {
output::statement("usage is one of:");
output::statement("\t" + argv[0] + " get <key>");
output::statement("\t" + argv[0] + " set <key> <value>");
return;
}
}

View File

@ -47,3 +47,16 @@ bool Bottle::save_config() {
configstream << this->config.dump(4);
return true;
}
string Bottle::get_config(string key) {
if (this->config.find(key) != this->config.end()) {
return this->config[key];
} else {
return "";
}
}
bool Bottle::set_config(string key, string value) {
this->config[key] = value;
return true;
}