diff --git a/libssu/ssurepomanager.cpp b/libssu/ssurepomanager.cpp index 1a84219..4cfd1b1 100644 --- a/libssu/ssurepomanager.cpp +++ b/libssu/ssurepomanager.cpp @@ -307,9 +307,15 @@ QStringList SsuRepoManager::repoVariables(QHash *storageHash, QStringList configSections; SsuSettings repoSettings(SSU_REPO_CONFIGURATION, QSettings::IniFormat); - // fill in all arbitrary variables from ssu.ini + // fill in all arbitrary repo specific variables from ssu.ini var.variableSection(settings, "repository-url-variables", storageHash); + // fill in all global variables from ssu.ini + // TODO: should be handled somewhere in core variable logic once variables + // are more widely used outside of repository urls, for now this is + // just for easier migration to "full" variable usage at a later point. + var.variableSection(settings, "global-variables", storageHash); + // add/overwrite some of the variables with sane ones if (rnd){ storageHash->insert("flavour", diff --git a/ssucli/ssucli.cpp b/ssucli/ssucli.cpp index 47bd444..0a9a561 100644 --- a/ssucli/ssucli.cpp +++ b/ssucli/ssucli.cpp @@ -13,6 +13,7 @@ #include "libssu/ssudeviceinfo.h" #include "libssu/ssurepomanager.h" #include "libssu/ssucoreconfig.h" +#include "libssu/ssuvariables.h" #include @@ -470,6 +471,47 @@ void SsuCli::optRepos(QStringList opt){ state = Idle; } +void SsuCli::optSet(QStringList opt){ + QTextStream qout(stdout); + SsuVariables var; + SsuCoreConfig *settings = SsuCoreConfig::instance(); + QHash storageHash; + + // set repository specific variable + if (opt.count() == 5 && opt.at(2) == "-r"){ + settings->setValue("repository-url-variables/" + opt.at(3), opt.at(4)); + // clear repo specific variable + } else if (opt.count() == 4 && opt.at(2) == "-r"){ + settings->remove("repository-url-variables/" + opt.at(3)); + // list repo specific variables + } else if (opt.count() == 3 && opt.at(2) == "-r"){ + qout << "Repository specific variables:" << endl << endl; + var.variableSection(settings, "repository-url-variables", &storageHash); + // set global variable + } else if (opt.count() == 4){ + settings->setValue("global-variables/" + opt.at(2), opt.at(3)); + // clear global variable + } else if (opt.count() == 3){ + settings->remove("global-variables/" + opt.at(2)); + // list global variables + } else if (opt.count() == 2){ + qout << "Global variables:" << endl << endl; + var.variableSection(settings, "global-variables", &storageHash); + } + + settings->sync(); + + if (!storageHash.isEmpty()){ + QHash::const_iterator i = storageHash.constBegin(); + while (i != storageHash.constEnd()){ + qout << i.key() << "=" << i.value() << endl; + i++; + } + } + + state = Idle; +} + void SsuCli::optStatus(QStringList opt){ QTextStream qout(stdout); QTextStream qerr(stderr); @@ -579,6 +621,7 @@ void SsuCli::run(){ "release", "re", 0, -1, &SsuCli::optRelease, "update", "up", 0, -1, &SsuCli::optUpdateCredentials, "domain", "do", 0, -1, &SsuCli::optDomain, + "set", "set", 0, -1, &SsuCli::optSet, }; bool found = false; @@ -646,11 +689,15 @@ void SsuCli::usage(QString message){ << "\tdisablerepo, dr \tdisable this repository" << endl << endl << "Configuration management:" << endl - << "\tflavour, fl \tdisplay flavour used (RnD only)" << endl - << "\t [newflavour] \tset new flavour" << endl - << "\trelease, re \tdisplay release used" << endl - << "\t [-r] \tuse RnD release" << endl - << "\t [newrelease] \tset new (RnD)release" << endl + << "\tflavour, fl \tdisplay flavour used (RnD only)" << endl + << "\t [newflavour] \tset new flavour" << endl + << "\trelease, re \tdisplay release used" << endl + << "\t [-r] \tuse RnD release" << endl + << "\t [newrelease] \tset new (RnD)release" << endl + << "\tset \tdisplay global variables" << endl + << "\t [-r] \toperate on repository only variables" << endl + << "\t \tdisplay value of " << endl + << "\t \tset value of to " << endl << endl << "Device management:" << endl << "\tstatus, s \tprint registration status and device information" << endl diff --git a/ssucli/ssucli.h b/ssucli/ssucli.h index 051520d..91380c1 100644 --- a/ssucli/ssucli.h +++ b/ssucli/ssucli.h @@ -40,6 +40,7 @@ class SsuCli: public QObject { void optRegister(QStringList opt); void optRelease(QStringList opt); void optRepos(QStringList opt); + void optSet(QStringList opt); void optStatus(QStringList opt); void optUpdateCredentials(QStringList opt); void optUpdateRepos(QStringList opt);