Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
preprocessor_list.cpp
Go to the documentation of this file.
2
3void PreprocessorList::print_containers(std::vector<ContainerInfo>& containers) {
4 size_t color_offset = no_color ? 0 :10;
5 std::cout << std::left
6 << std::setw(29 + color_offset) << BOLD("CACHE CONTAINER") << " "
7 << std::setw(12 + color_offset) << BOLD("ID") << " "
8 << std::setw(10 + color_offset) << BOLD("DISK USAGE") << " "
9 << BOLD("EXTRA")
10 << "\n";
11
12 for (const auto& container : containers) {
13 std::cout << std::left << std::setw(29 + color_offset + color_offset) << BOLD(BLUE(container.name)) << " "
14 << std::left << std::setw(12) << container.id << " "
15 << std::right << std::setw(10) << container.disk_usage << " "
16 << std::left << container.extra
17 << "\n";
18 }
19}
20
22
24 no_color = options.args.count("no-color") > 0;
25 return true;
26}
27
28bool PreprocessorList::run([[maybe_unused]] const ParsedOptions& options) {
29 fs::path base_path = Config::config().base_path;
30
31 std::vector<ContainerInfo> containers;
32
33 for (const auto& entry : fs::directory_iterator(base_path)) {
34 if (!fs::is_directory(entry)) continue;
35
36 ContainerInfo container;
37 container.name = entry.path().filename().string();
38 container.id = Utils::hash(container.name);
39 container.disk_usage = Utils::format_size(Utils::folder_size(entry.path()));
40 container.extra = "";
41 containers.push_back(container);
42 }
43
44 print_containers(containers);
45
46 return true;
47}
const CliOption * options() const final
static Config & config()
Gets the singleton configuration instance.
Definition config.cpp:37
fs::path base_path
Default base path for temporary files.
Definition config.hpp:42
bool run(const ParsedOptions &options) override
Executes the main logic of the command.
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
@ BOLD
Bold text.
Definition utils.hpp:123
@ 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:168
std::uintmax_t folder_size(const fs::path &folder)
Calculates the total size of all regular files in a folder.
Definition utils.cpp:151
std::string hash(const std::string &content)
Computes a simple hash of a string.
Definition utils.cpp:136
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.