Browse Source

Manager: Add verbose flag and store it in new Config class

Check the verbosity in the Dotfile class when printing file operations.
master
Riyyi 3 years ago
parent
commit
c032373940
  1. 25
      src/config.h
  2. 5
      src/dotfile.cpp
  3. 5
      src/main.cpp

25
src/config.h

@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#ifndef CONFIG_H
#define CONFIG_H
#include "util/singleton.h"
class Config : public Util::Singleton<Config> {
public:
Config(s) {}
virtual ~Config() {}
void setVerbose(bool verbose) { m_verbose = verbose; }
bool verbose() const { return m_verbose; }
private:
bool m_verbose { false };
};
#endif // CONFIG_H

5
src/dotfile.cpp

@ -15,6 +15,7 @@
#include <unistd.h> // geteuid, getlogin, setegid, seteuid
#include <vector>
#include "config.h"
#include "dotfile.h"
#include "machine.h"
#include "util/file.h"
@ -199,14 +200,18 @@ void Dotfile::sync(SyncType type,
if (std::filesystem::is_regular_file(from)) {
auto directory = to.parent_path();
if (!directory.empty() && !std::filesystem::exists(directory)) {
if (Config::the().verbose()) {
printf("Created directory: '%s'\n", directory.c_str());
}
std::filesystem::create_directories(directory, error);
printError(to.relative_path().parent_path(), error);
}
}
// Copy the file or directory
if (Config::the().verbose()) {
printf("'%s' -> '%s'\n", from.c_str(), to.c_str());
}
std::filesystem::copy(from, to, copyOptions, error);
printError(to, error);

5
src/main.cpp

@ -10,6 +10,7 @@
#include <unistd.h> // gethostname
#include <vector>
#include "config.h"
#include "dotfile.h"
#include "package.h"
#include "util/argparser.h"
@ -39,6 +40,7 @@ int main(int argc, const char* argv[])
bool install = false;
bool pull = false;
bool pushOrStore = false;
bool verbose = false;
std::vector<std::string> targets {};
@ -51,6 +53,7 @@ int main(int argc, const char* argv[])
argParser.addOption(install, 'i', "install", nullptr, nullptr);
argParser.addOption(pull, 'l', "pull", nullptr, nullptr);
argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr);
argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr);
argParser.addArgument(targets, "targets", nullptr, nullptr, Util::ArgParser::Required::No);
argParser.parse(argc, argv);
@ -62,6 +65,8 @@ int main(int argc, const char* argv[])
Util::Timer t;
Config::the().setVerbose(verbose);
if (fileOperation) {
Dotfile::the().setExcludePaths({
{ Dotfile::ExcludeType::File, "dotfiles.sh" },

Loading…
Cancel
Save