Manager: Add verbose flag and store it in new Config class
Check the verbosity in the Dotfile class when printing file operations.
This commit is contained in:
@@ -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
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <unistd.h> // geteuid, getlogin, setegid, seteuid
|
#include <unistd.h> // geteuid, getlogin, setegid, seteuid
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "dotfile.h"
|
#include "dotfile.h"
|
||||||
#include "machine.h"
|
#include "machine.h"
|
||||||
#include "util/file.h"
|
#include "util/file.h"
|
||||||
@@ -199,14 +200,18 @@ void Dotfile::sync(SyncType type,
|
|||||||
if (std::filesystem::is_regular_file(from)) {
|
if (std::filesystem::is_regular_file(from)) {
|
||||||
auto directory = to.parent_path();
|
auto directory = to.parent_path();
|
||||||
if (!directory.empty() && !std::filesystem::exists(directory)) {
|
if (!directory.empty() && !std::filesystem::exists(directory)) {
|
||||||
|
if (Config::the().verbose()) {
|
||||||
printf("Created directory: '%s'\n", directory.c_str());
|
printf("Created directory: '%s'\n", directory.c_str());
|
||||||
|
}
|
||||||
std::filesystem::create_directories(directory, error);
|
std::filesystem::create_directories(directory, error);
|
||||||
printError(to.relative_path().parent_path(), error);
|
printError(to.relative_path().parent_path(), error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the file or directory
|
// Copy the file or directory
|
||||||
|
if (Config::the().verbose()) {
|
||||||
printf("'%s' -> '%s'\n", from.c_str(), to.c_str());
|
printf("'%s' -> '%s'\n", from.c_str(), to.c_str());
|
||||||
|
}
|
||||||
std::filesystem::copy(from, to, copyOptions, error);
|
std::filesystem::copy(from, to, copyOptions, error);
|
||||||
printError(to, error);
|
printError(to, error);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <unistd.h> // gethostname
|
#include <unistd.h> // gethostname
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "dotfile.h"
|
#include "dotfile.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "util/argparser.h"
|
#include "util/argparser.h"
|
||||||
@@ -39,6 +40,7 @@ int main(int argc, const char* argv[])
|
|||||||
bool install = false;
|
bool install = false;
|
||||||
bool pull = false;
|
bool pull = false;
|
||||||
bool pushOrStore = false;
|
bool pushOrStore = false;
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
std::vector<std::string> targets {};
|
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(install, 'i', "install", nullptr, nullptr);
|
||||||
argParser.addOption(pull, 'l', "pull", nullptr, nullptr);
|
argParser.addOption(pull, 'l', "pull", nullptr, nullptr);
|
||||||
argParser.addOption(pushOrStore, 's', "push", 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.addArgument(targets, "targets", nullptr, nullptr, Util::ArgParser::Required::No);
|
||||||
argParser.parse(argc, argv);
|
argParser.parse(argc, argv);
|
||||||
@@ -62,6 +65,8 @@ int main(int argc, const char* argv[])
|
|||||||
|
|
||||||
Util::Timer t;
|
Util::Timer t;
|
||||||
|
|
||||||
|
Config::the().setVerbose(verbose);
|
||||||
|
|
||||||
if (fileOperation) {
|
if (fileOperation) {
|
||||||
Dotfile::the().setExcludePaths({
|
Dotfile::the().setExcludePaths({
|
||||||
{ Dotfile::ExcludeType::File, "dotfiles.sh" },
|
{ Dotfile::ExcludeType::File, "dotfiles.sh" },
|
||||||
|
|||||||
Reference in New Issue
Block a user