diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..903c01f --- /dev/null +++ b/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 { +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 diff --git a/src/dotfile.cpp b/src/dotfile.cpp index fa57a22..de38dcd 100644 --- a/src/dotfile.cpp +++ b/src/dotfile.cpp @@ -15,6 +15,7 @@ #include // geteuid, getlogin, setegid, seteuid #include +#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)) { - printf("Created directory: '%s'\n", directory.c_str()); + 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 - printf("'%s' -> '%s'\n", from.c_str(), to.c_str()); + if (Config::the().verbose()) { + printf("'%s' -> '%s'\n", from.c_str(), to.c_str()); + } std::filesystem::copy(from, to, copyOptions, error); printError(to, error); diff --git a/src/main.cpp b/src/main.cpp index 2c78e15..fa6ecf7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include // gethostname #include +#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 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" },