ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
preprocessor_clean.cpp
Go to the documentation of this file.
4#include <filesystem>
5#include <iostream>
6#include <string>
7
8namespace fs = std::filesystem;
9
11 clean_all = options.has("all");
12 return true;
13}
14
16 fs::path base_path = Config::config().base_path;
17
18 if (base_path.filename() != "arkanjo") {
19 throw CLIError("Invalid cache directory.");
20 }
21
22 try {
23 fs::path cache_dir = clean_all ? base_path : base_path / Config::config().name_container;
24 cache_dir = fs::weakly_canonical(cache_dir);
25
26 if (fs::exists(cache_dir)) {
27 if (clean_all) {
28 for (const auto& entry : fs::directory_iterator(base_path))
29 fs::remove_all(entry.path());
30
31 std::cout << "Successfully cleaned all cache directories in: " << cache_dir.string() << "\n";
32 } else {
33 fs::remove_all(cache_dir);
34
35 std::cout << "Successfully cleaned cache directory: " << cache_dir.string() << "\n";
36 }
37 }
38 else std::cout << "Cache directory does not exist, nothing to clean.\n";
39
40 } catch (const std::exception& e) {
41 throw CLIError("Error while cleaning cache: " + std::string(e.what()));
42 }
43 return true;
44}
Base class for CLI-related errors.
Definition: cli_error.hpp:10
const CliOption * options() const final
static Config & config()
Gets the singleton configuration instance.
Definition: config.cpp:68
bool run(const ParsedOptions &options) override
Executes the main logic of the command.
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
Configuration management interface.
Remove cached application data.
std::filesystem::path base_path
Default base path for temporary files.
Definition: schema.hpp:16
std::filesystem::path name_container
Name of the cache container.
Definition: schema.hpp:18