ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
preprocessor_list.cpp
Go to the documentation of this file.
2
5
6void PreprocessorList::print_containers(std::vector<ContainerInfo>& containers) {
7 size_t color_offset = no_color ? 0 :10;
8 std::cout << std::left
9 << std::setw(29 + color_offset) << BOLD("CACHE CONTAINER") << " "
10 << std::setw(12 + color_offset) << BOLD("ID") << " "
11 << std::setw(10 + color_offset) << BOLD("DISK USAGE") << " "
12 << BOLD("EXTRA")
13 << "\n";
14
15 for (const auto& container : containers) {
16 std::cout << std::left << std::setw(29 + color_offset + color_offset) << BOLD(BLUE(container.name)) << " "
17 << std::left << std::setw(12) << container.id << " "
18 << std::right << std::setw(10) << container.disk_usage << " "
19 << std::left << container.extra
20 << "\n";
21 }
22}
23
25
27 no_color = options.has("no-color");
28 return true;
29}
30
31bool PreprocessorList::run([[maybe_unused]] const ParsedOptions& options) {
32 fs::path base_path = Config::config().base_path;
33
34 std::vector<ContainerInfo> containers;
35
36 for (const auto& entry : fs::directory_iterator(base_path)) {
37 if (!fs::is_directory(entry)) continue;
38
39 ContainerInfo container;
40 container.name = entry.path().filename().string();
41
44
45 container.id = Utils::hash(container.name);
46
47 container.disk_usage = Utils::format_size(params.size);
48 if (params.size <= 0) {
49 container.disk_usage = Utils::format_size(Utils::folder_size(entry.path()));
50 }
51
52 auto version = !params.version.empty() ? "v" + params.version : "";
53 if (!Preprocess_State::is_cache_compatible(params.version)) {
54 version = RED(version);
55 }
56
57 container.extra = version;
58 containers.push_back(container);
59 }
60
61 print_containers(containers);
62
63 return true;
64}
const CliOption * options() const final
static Config & config()
Gets the singleton configuration instance.
Definition: config.cpp:68
static PreprocessRunParams read_current_run_params()
read preprocessing parameters runs
static bool is_cache_compatible(const std::string &cache_version)
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.
@ BOLD
Bold text.
Definition: utils.hpp:123
@ RED
Red color.
Definition: utils.hpp:113
@ BLUE
Blue color.
Definition: utils.hpp:116
std::string format_size(std::uintmax_t bytes)
Formats a byte size into a human-readable string.
Definition: utils.cpp:181
std::uintmax_t folder_size(const fs::path &folder)
Calculates the total size of all regular files in a folder.
Definition: utils.cpp:164
std::string hash(const std::string &content)
Computes a simple hash of a string.
Definition: utils.cpp:149
Interface for listing preprocessors in the system.
Container metadata representation.
std::string name
Container name.
std::string extra
Additional info.
std::string id
Unique container ID.
std::string disk_usage
Human-readable disk usage.
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