Browse Source

Manager: Switch from Util to the ruc library

master
Riyyi 2 years ago
parent
commit
4927e35bfc
  1. 14
      src/config.cpp
  2. 10
      src/config.h
  3. 6
      src/dotfile.cpp
  4. 4
      src/dotfile.h
  5. 4
      src/machine.cpp
  6. 4
      src/machine.h
  7. 12
      src/main.cpp
  8. 16
      src/package.cpp
  9. 4
      src/package.h

14
src/config.cpp

@ -12,8 +12,8 @@
#include <vector> #include <vector>
#include "config.h" #include "config.h"
#include "util/json/json.h" #include "ruc/json/json.h"
#include "util/meta/assert.h" #include "ruc/meta/assert.h"
Config::Config(s) Config::Config(s)
: m_workingDirectory(std::filesystem::current_path()) : m_workingDirectory(std::filesystem::current_path())
@ -51,7 +51,7 @@ void Config::parseConfigFile()
return; return;
} }
Util::Json json; ruc::Json json;
std::ifstream file(m_config); std::ifstream file(m_config);
if (!file.is_open()) { if (!file.is_open()) {
@ -72,17 +72,17 @@ void Config::parseConfigFile()
// ----------------------------------------- // -----------------------------------------
void toJson(Util::Json& json, const Settings& settings) void toJson(ruc::Json& json, const Settings& settings)
{ {
json = Util::Json { json = ruc::Json {
{ "ignorePatterns", settings.ignorePatterns }, { "ignorePatterns", settings.ignorePatterns },
{ "systemPatterns", settings.systemPatterns } { "systemPatterns", settings.systemPatterns }
}; };
} }
void fromJson(const Util::Json& json, Settings& settings) void fromJson(const ruc::Json& json, Settings& settings)
{ {
VERIFY(json.type() == Util::Json::Type::Object); VERIFY(json.type() == ruc::Json::Type::Object);
if (json.exists("ignorePatterns")) { if (json.exists("ignorePatterns")) {
json.at("ignorePatterns").getTo(settings.ignorePatterns); json.at("ignorePatterns").getTo(settings.ignorePatterns);

10
src/config.h

@ -11,8 +11,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "util/json/json.h" #include "ruc/json/json.h"
#include "util/singleton.h" #include "ruc/singleton.h"
struct Settings { struct Settings {
std::vector<std::string> ignorePatterns { std::vector<std::string> ignorePatterns {
@ -31,7 +31,7 @@ struct Settings {
}; };
}; };
class Config : public Util::Singleton<Config> { class Config : public ruc::Singleton<Config> {
public: public:
Config(s); Config(s);
virtual ~Config(); virtual ~Config();
@ -65,5 +65,5 @@ private:
// Json arbitrary type conversion functions // Json arbitrary type conversion functions
void toJson(Util::Json& object, const Settings& settings); void toJson(ruc::Json& object, const Settings& settings);
void fromJson(const Util::Json& object, Settings& settings); void fromJson(const ruc::Json& object, Settings& settings);

6
src/dotfile.cpp

@ -18,8 +18,8 @@
#include "config.h" #include "config.h"
#include "dotfile.h" #include "dotfile.h"
#include "machine.h" #include "machine.h"
#include "util/file.h" #include "ruc/file.h"
#include "util/meta/assert.h" #include "ruc/meta/assert.h"
Dotfile::Dotfile(s) Dotfile::Dotfile(s)
{ {
@ -373,7 +373,7 @@ void Dotfile::sync(SyncType type,
void Dotfile::selectivelyCommentOrUncomment(const std::string& path) void Dotfile::selectivelyCommentOrUncomment(const std::string& path)
{ {
Util::File dotfile(path); ruc::File dotfile(path);
const std::string search[3] = { const std::string search[3] = {
"distro=", "distro=",

4
src/dotfile.h

@ -13,9 +13,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "util/singleton.h" #include "ruc/singleton.h"
class Dotfile : public Util::Singleton<Dotfile> { class Dotfile : public ruc::Singleton<Dotfile> {
public: public:
Dotfile(s); Dotfile(s);
virtual ~Dotfile(); virtual ~Dotfile();

4
src/machine.cpp

@ -9,7 +9,7 @@
#include <unistd.h> // gethostname, getlogin #include <unistd.h> // gethostname, getlogin
#include "machine.h" #include "machine.h"
#include "util/file.h" #include "ruc/file.h"
Machine::Machine(s) Machine::Machine(s)
{ {
@ -26,7 +26,7 @@ Machine::~Machine()
void Machine::fetchDistro() void Machine::fetchDistro()
{ {
Util::File osRelease("/etc/os-release"); ruc::File osRelease("/etc/os-release");
std::istringstream stream(osRelease.data()); std::istringstream stream(osRelease.data());
for (std::string line; std::getline(stream, line);) { for (std::string line; std::getline(stream, line);) {
if (line.find("ID=") == 0) { if (line.find("ID=") == 0) {

4
src/machine.h

@ -10,9 +10,9 @@
#include <pwd.h> // passwd #include <pwd.h> // passwd
#include <string> #include <string>
#include "util/singleton.h" #include "ruc/singleton.h"
class Machine : public Util::Singleton<Machine> { class Machine : public ruc::Singleton<Machine> {
public: public:
Machine(s); Machine(s);
virtual ~Machine(); virtual ~Machine();

12
src/main.cpp

@ -11,8 +11,8 @@
#include "config.h" #include "config.h"
#include "dotfile.h" #include "dotfile.h"
#include "package.h" #include "package.h"
#include "util/argparser.h" #include "ruc/argparser.h"
#include "util/timer.h" #include "ruc/timer.h"
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
@ -28,7 +28,7 @@ int main(int argc, const char* argv[])
std::vector<std::string> targets {}; std::vector<std::string> targets {};
Util::ArgParser argParser; ruc::ArgParser argParser;
argParser.addOption(fileOperation, 'F', "file", nullptr, nullptr); argParser.addOption(fileOperation, 'F', "file", nullptr, nullptr);
argParser.addOption(packageOperation, 'P', "package", nullptr, nullptr); argParser.addOption(packageOperation, 'P', "package", nullptr, nullptr);
argParser.addOption(helpOperation, 'h', "help", nullptr, nullptr); argParser.addOption(helpOperation, 'h', "help", nullptr, nullptr);
@ -39,7 +39,7 @@ int main(int argc, const char* argv[])
argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr); argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr);
argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr); argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr);
argParser.addArgument(targets, "targets", nullptr, nullptr, Util::ArgParser::Required::No); argParser.addArgument(targets, "targets", nullptr, nullptr, ruc::ArgParser::Required::No);
argParser.parse(argc, argv); argParser.parse(argc, argv);
if (fileOperation + packageOperation + helpOperation > 1) { if (fileOperation + packageOperation + helpOperation > 1) {
@ -48,7 +48,7 @@ int main(int argc, const char* argv[])
} }
#ifndef NDEBUG #ifndef NDEBUG
Util::Timer t; ruc::Timer t;
#endif #endif
Config::the().setVerbose(verbose); Config::the().setVerbose(verbose);
@ -89,7 +89,7 @@ int main(int argc, const char* argv[])
} }
#ifndef NDEBUG #ifndef NDEBUG
printf("%fms\n", t.elapsedNanoseconds() / 1000000.0); printf("%fms\n", t.elapsedNanoseconds() / 1000000.0);
#endif #endif
return 0; return 0;

16
src/package.cpp

@ -16,9 +16,9 @@
#include "machine.h" #include "machine.h"
#include "package.h" #include "package.h"
#include "util/file.h" #include "ruc/file.h"
#include "util/shell.h" #include "ruc/shell.h"
#include "util/system.h" #include "ruc/system.h"
Package::Package(s) Package::Package(s)
{ {
@ -80,7 +80,7 @@ void Package::store()
return; return;
} }
auto packageFile = Util::File::create("./packages"); auto packageFile = ruc::File::create("./packages");
packageFile.clear(); packageFile.clear();
packageFile.append(packagesOrEmpty.value()); packageFile.append(packagesOrEmpty.value());
packageFile.flush(); packageFile.flush();
@ -126,15 +126,15 @@ void Package::installOrAurInstall(InstallType type)
std::string command = ""; std::string command = "";
Util::System $; ruc::System $;
if (m_distro == Distro::Arch) { if (m_distro == Distro::Arch) {
// Grab everything off enabled official repositories that is in the list // Grab everything off enabled official repositories that is in the list
auto repoList = $("pacman -Ssq") | $("grep -xf ./packages"); auto repoList = $("pacman -Ssq") | $("grep -xf ./packages");
if (type == InstallType::AurInstall) { if (type == InstallType::AurInstall) {
// Determine which packages in the list are from the AUR // Determine which packages in the list are from the AUR
// NOTE: Util::System does not support commands with newlines // NOTE: ruc::System does not support commands with newlines
auto aurList = Util::Shell()("grep -vx '" + repoList.output() + "' ./packages"); auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' ./packages");
command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output(); command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output();
} }
else { else {
@ -224,7 +224,7 @@ std::optional<std::string> Package::getPackageList()
std::string packages; std::string packages;
Util::System $; ruc::System $;
if (m_distro == Distro::Arch) { if (m_distro == Distro::Arch) {
auto basePackages = $("pactree -u base").tail(2, true); auto basePackages = $("pactree -u base").tail(2, true);
auto develPackages = $("pacman -Qqg base-devel"); auto develPackages = $("pacman -Qqg base-devel");

4
src/package.h

@ -11,9 +11,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "util/singleton.h" #include "ruc/singleton.h"
class Package : public Util::Singleton<Package> { class Package : public ruc::Singleton<Package> {
public: public:
Package(s); Package(s);
virtual ~Package(); virtual ~Package();

Loading…
Cancel
Save