implement tclap into cellar config (behavior remains mostly unchanged)

This commit is contained in:
Nicholas O'Connor 2017-04-14 22:40:58 -07:00
parent 873d131cc9
commit 58c96411a0
2 changed files with 26 additions and 9 deletions

View File

@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
cmdparse.parse(argc, argv); cmdparse.parse(argc, argv);
dryrun = dryrunarg.getValue(); dryrun = dryrunarg.getValue();
verbose = verbosearg.getValue(); verbose = dryrun || verbosearg.getValue();
// BULLSHIT: trying to use str.format on this string causes bizarre compiler errors // BULLSHIT: trying to use str.format on this string causes bizarre compiler errors
/*[[[cog /*[[[cog

View File

@ -1,10 +1,13 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "tclap/CmdLine.h"
#include "bottles.hpp" #include "bottles.hpp"
#include "cellar.hpp" #include "cellar.hpp"
#include "internal/config.hpp" #include "internal/config.hpp"
#include "output.hpp" #include "output.hpp"
#include "version.hpp"
using namespace std; using namespace std;
using namespace cellar; using namespace cellar;
@ -13,11 +16,28 @@ using namespace cellar::bottles;
using json = nlohmann::json; using json = nlohmann::json;
void cellar::config::config_command(int argc, vector<string> argv) { void cellar::config::config_command(int argc, vector<string> argv) {
if (argc == 1) { const string desc = "Change cellar configuration options";
output::error("not enough arguments"); const string versionstr = version::short_version();
return; TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false);
}
string command = argv[1]; TCLAP::SwitchArg globalarg("g", "global", "Use global user configuration (~/.local/share/cellar/cellar.json)");
cmdparse.add(globalarg);
TCLAP::UnlabeledValueArg<string> commandarg("command", "", true, "get", "command");
cmdparse.add(commandarg);
TCLAP::UnlabeledValueArg<string> keyarg("key", "", true, "", "key");
cmdparse.add(keyarg);
TCLAP::UnlabeledValueArg<string> valarg("value", "", false, "", "value");
cmdparse.add(valarg);
cmdparse.parse(argv);
bool global = globalarg.getValue();
string command = commandarg.getValue();
string key = keyarg.getValue();
string value = valarg.getValue();
// BULLSHIT: switch can't be used for strings, according to gcc // BULLSHIT: switch can't be used for strings, according to gcc
if (command == "get") { if (command == "get") {
@ -26,9 +46,6 @@ void cellar::config::config_command(int argc, vector<string> argv) {
return; return;
} }
string key = argv[2];
string value = active_bottle.get_config(key);
if (value != "") { if (value != "") {
output::statement(key + ": " + value); output::statement(key + ": " + value);
} else { } else {