From c877663932608016ba71b470e5bc2e3adf8272f9 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Fri, 24 Mar 2017 18:45:50 -0700 Subject: [PATCH] config command can get values now --- src/bottles/config/cli_handler.cpp | 28 +++++++++++++++++++++++++++- src/bottles/config/save_load.cpp | 13 +++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/bottles/config/cli_handler.cpp b/src/bottles/config/cli_handler.cpp index ded49cd..a0538b4 100644 --- a/src/bottles/config/cli_handler.cpp +++ b/src/bottles/config/cli_handler.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -18,5 +19,30 @@ void cellar::bottles::config_command(int argc, vector 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 "); + 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 "); + } else { + output::statement("usage is one of:"); + output::statement("\t" + argv[0] + " get "); + output::statement("\t" + argv[0] + " set "); + return; + } } diff --git a/src/bottles/config/save_load.cpp b/src/bottles/config/save_load.cpp index 43366c4..7787968 100644 --- a/src/bottles/config/save_load.cpp +++ b/src/bottles/config/save_load.cpp @@ -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; +}