-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCleanCommand.cpp
More file actions
105 lines (86 loc) · 1.98 KB
/
Copy pathCleanCommand.cpp
File metadata and controls
105 lines (86 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
*
* @file CleanCommand.cpp
* @author Gaspard Kirira
*
* Copyright 2025, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*/
#include <vix/cli/commands/CleanCommand.hpp>
#include <vix/cli/util/Ui.hpp>
#include <filesystem>
#include <iostream>
#include <vector>
#include <string>
namespace fs = std::filesystem;
namespace vix::commands
{
namespace
{
struct Target
{
std::string label;
fs::path path;
};
static std::vector<Target> targets()
{
return {
{".vix", fs::current_path() / ".vix"},
{"build", fs::current_path() / "build"}};
}
static bool remove_dir(const fs::path &p)
{
std::error_code ec;
fs::remove_all(p, ec);
return !ec;
}
}
int CleanCommand::run(const std::vector<std::string> &args)
{
(void)args;
vix::cli::util::section(std::cout, "Clean");
bool removedAny = false;
for (const auto &t : targets())
{
if (!fs::exists(t.path))
continue;
vix::cli::util::info_line(std::cout, "removing " + t.label + "/");
if (remove_dir(t.path))
{
removedAny = true;
}
else
{
vix::cli::util::warn_line(std::cout, "failed to remove " + t.label);
}
}
vix::cli::util::one_line_spacer(std::cout);
if (removedAny)
{
vix::cli::util::ok_line(std::cout, "Project cache cleaned");
}
else
{
vix::cli::util::warn_line(std::cout, "Nothing to clean");
}
return 0;
}
int CleanCommand::help()
{
std::cout
<< "vix clean\n"
<< "Remove local project cache directories.\n\n"
<< "Usage\n"
<< " vix clean\n\n"
<< "What it removes\n"
<< " • .vix/\n"
<< " • build/\n\n"
<< "Notes\n"
<< " • Does NOT remove global cache (~/.vix)\n";
return 0;
}
}