From 7c6965be4030a67ee7ee1b0e1fab63d8ca2e2b9b Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 1 Dec 2020 18:47:18 +0900 Subject: [PATCH] Remove cache command temporarily --- include/poac/opts.hpp | 1 - include/poac/opts/cache.hpp | 126 ------------------------------------ 2 files changed, 127 deletions(-) delete mode 100644 include/poac/opts/cache.hpp diff --git a/include/poac/opts.hpp b/include/poac/opts.hpp index 58fb189d8..9dfb5078e 100644 --- a/include/poac/opts.hpp +++ b/include/poac/opts.hpp @@ -2,7 +2,6 @@ #define POAC_OPTS_HPP #include -#include #include #include #include diff --git a/include/poac/opts/cache.hpp b/include/poac/opts/cache.hpp deleted file mode 100644 index 849189686..000000000 --- a/include/poac/opts/cache.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef POAC_OPTS_CACHE_HPP -#define POAC_OPTS_CACHE_HPP - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace poac::opts::cache { - inline const clap::subcommand cli = - clap::subcommand("cache") - .about("Manipulate cache files") - .arg(clap::opt("all", "Manipulate all caches").short_("a")) - .arg(clap::opt("pattern", "Regex pattern").value_name("PATTERN")) - ; - - struct Options { - enum class SubCmd { - Root, - List, - Clean, - }; - SubCmd subcmd; - std::optional pattern; - bool all; - std::vector files; - }; - - [[nodiscard]] std::optional - clean(cache::Options&& opts) { - if (opts.all) { - std::filesystem::remove_all(io::path::poac_cache_dir); - } else if (!opts.files.empty()) { - for (const auto& f : opts.files) { - const std::filesystem::path cache_package = io::path::poac_cache_dir / f; - if (io::path::validate_dir(cache_package)) { - std::filesystem::remove_all(cache_package); - std::cout << cache_package << " is deleted" << std::endl; - } else { - std::cout << termcolor2::red << cache_package << " not found" - << termcolor2::reset << std::endl; - } - } - } else { - return core::except::Error::InvalidSecondArg::Cache; - } - return std::nullopt; - } - - [[nodiscard]] std::optional - list(cache::Options&& opts) { - if (opts.pattern) { - for (const auto& e : boost::make_iterator_range( - std::filesystem::directory_iterator(io::path::poac_cache_dir), {}) - ) { - const std::string cache_file = e.path().filename().string(); - if (std::regex_match(cache_file, opts.pattern.value())) - std::cout << cache_file << std::endl; - } - } else { - for (const auto& e : boost::make_iterator_range( - std::filesystem::directory_iterator(io::path::poac_cache_dir), {}) - ) { - std::cout << e.path().filename().string() << std::endl; - } - } - return std::nullopt; - } - - [[nodiscard]] std::optional - root() { - std::cout << io::path::poac_cache_dir.string() << std::endl; - return std::nullopt; - } - - [[nodiscard]] std::optional - cache(cache::Options&& opts) { - switch (opts.subcmd) { - case cache::Options::SubCmd::Root: - return root(); - case cache::Options::SubCmd::List: - return list(std::move(opts)); - case cache::Options::SubCmd::Clean: - return clean(std::move(opts)); - default: - throw std::logic_error( - "To access out of range of the " - "enumeration values is undefined behavior."); - } - } - - [[nodiscard]] std::optional - exec(std::future>&&, std::vector&& args) { - if (args.empty()) { - return core::except::Error::InvalidSecondArg::Cache; - } - - cache::Options opts{}; - if (args[0] == "root" && args.size() == 1) { - opts.subcmd = cache::Options::SubCmd::Root; - } else if (args[0] == "list") { - opts.subcmd = cache::Options::SubCmd::List; - opts.pattern = util::argparse::use_get(args, "--pattern"); - } else if (args[0] == "clean") { - opts.subcmd = cache::Options::SubCmd::Clean; - opts.all = util::argparse::use(args, "-a", "--all"); - opts.files = std::vector(args.begin() + 1, args.begin() + args.size()); - } else { - return core::except::Error::InvalidSecondArg::Cache; - } - return cache::cache(std::move(opts)); - } -} // end namespace -#endif // !POAC_OPTS_CACHE_HPP