diff --git a/.gitignore b/.gitignore index e10b1a6..c2c37d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.o *.so */.deps +*.swp build/ diff --git a/src/bottles/config/cli_handler.cpp b/src/bottles/config/cli_handler.cpp index a0538b4..4b2331b 100644 --- a/src/bottles/config/cli_handler.cpp +++ b/src/bottles/config/cli_handler.cpp @@ -31,14 +31,34 @@ void cellar::bottles::config_command(int argc, vector argv) { Bottle active_bottle = Bottle(homedir + "/.wine"); active_bottle.load_config(); - string value = active_bottle.get_config(argv[2]); + string key = argv[2]; + string value = active_bottle.get_config(key); + if (value != "") { - output::statement(argv[2] + ": " + value); + output::statement(key + ": " + value); } else { - output::error(argv[2] + " is not defined"); + output::error(key + " is not defined"); } } else if (command == "set") { - output::statement("usage: " + argv[0] + " set "); + if (argc < 4) { + output::statement("usage: " + argv[0] + " set "); + 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); + + if (active_bottle.set_config(key, newvalue)) { + output::statement(key + ": " + newvalue + " (was " + oldvalue + ")"); + } else { + output::error(key + ": " + oldvalue); + } } else { output::statement("usage is one of:"); output::statement("\t" + argv[0] + " get "); diff --git a/src/bottles/config/save_load.cpp b/src/bottles/config/save_load.cpp index 7787968..2dab39a 100644 --- a/src/bottles/config/save_load.cpp +++ b/src/bottles/config/save_load.cpp @@ -58,5 +58,6 @@ string Bottle::get_config(string key) { bool Bottle::set_config(string key, string value) { this->config[key] = value; + this->save_config(); return true; } diff --git a/src/output.cpp b/src/output.cpp index b84c20c..5a64e68 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -49,7 +49,7 @@ void cellar::output::warning(string str_message, bool verbose) { cerr << str_message << endl; } -void cellar::output::warning(string str_message) { statement(str_message, false); } +void cellar::output::warning(string str_message) { warning(str_message, false); } void cellar::output::error(string str_message, bool verbose) { if (verbose and !cellar::verbose) { return; } @@ -64,5 +64,5 @@ void cellar::output::error(string str_message, bool verbose) { cerr << str_message << endl; } -void cellar::output::error(string str_message) { statement(str_message, false); } +void cellar::output::error(string str_message) { error(str_message, false); }