implement tclap into cellar config (behavior remains mostly unchanged)
This commit is contained in:
		@@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
 | 
			
		||||
        cmdparse.parse(argc, argv);
 | 
			
		||||
 | 
			
		||||
        dryrun = dryrunarg.getValue();
 | 
			
		||||
        verbose = verbosearg.getValue();
 | 
			
		||||
        verbose = dryrun || verbosearg.getValue();
 | 
			
		||||
 | 
			
		||||
        // BULLSHIT: trying to use str.format on this string causes bizarre compiler errors
 | 
			
		||||
        /*[[[cog
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,13 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "tclap/CmdLine.h"
 | 
			
		||||
 | 
			
		||||
#include "bottles.hpp"
 | 
			
		||||
#include "cellar.hpp"
 | 
			
		||||
#include "internal/config.hpp"
 | 
			
		||||
#include "output.hpp"
 | 
			
		||||
#include "version.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace cellar;
 | 
			
		||||
@@ -13,11 +16,28 @@ using namespace cellar::bottles;
 | 
			
		||||
using json = nlohmann::json;
 | 
			
		||||
 | 
			
		||||
void cellar::config::config_command(int argc, vector<string> argv) {
 | 
			
		||||
    if (argc == 1) {
 | 
			
		||||
        output::error("not enough arguments");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    string command = argv[1];
 | 
			
		||||
    const string desc = "Change cellar configuration options";
 | 
			
		||||
    const string versionstr = version::short_version();
 | 
			
		||||
    TCLAP::CmdLine cmdparse(desc, ' ', versionstr, false);
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
    if (command == "get") {
 | 
			
		||||
@@ -26,9 +46,6 @@ void cellar::config::config_command(int argc, vector<string> argv) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        string key = argv[2];
 | 
			
		||||
        string value = active_bottle.get_config(key);
 | 
			
		||||
        
 | 
			
		||||
        if (value != "") {
 | 
			
		||||
            output::statement(key + ": " + value);
 | 
			
		||||
        } else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user