Skip to content

Commit b473a6c

Browse files
committed
feat(cli): add task system, fmt command, and project utilities
- add TaskCommand with: • built-in tasks (dev, run, fmt, check, build, test) • support for vix.json custom tasks • task dependencies (deps) • multiple commands execution (commands array) • variable system (global + task-level) • environment injection (env) • working directory override (cwd) • cross-platform overrides (linux, macos, windows) • interactive task selector (TTY) - add FmtCommand: • format C++ code using clang-format • support file inputs, --check, --ignore, --quiet • default scan: src/ and include/ - add CleanCommand: • clean build artifacts and cache - add ResetCommand: • reset project state (build/cache) - update CLI dispatcher and command registry - improve developer workflow with reusable task orchestration
1 parent 1df5435 commit b473a6c

10 files changed

Lines changed: 2035 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
*
3+
* @file CleanCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_CLEAN_COMMAND_HPP
14+
#define VIX_CLEAN_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
class CleanCommand
22+
{
23+
public:
24+
static int run(const std::vector<std::string> &args);
25+
static int help();
26+
};
27+
}
28+
29+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
*
3+
* @file FmtCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_FMT_COMMAND_HPP
14+
#define VIX_FMT_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
class FmtCommand
22+
{
23+
public:
24+
static int run(const std::vector<std::string> &args);
25+
static int help();
26+
};
27+
}
28+
29+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <string>
5+
6+
namespace vix::commands
7+
{
8+
class ResetCommand
9+
{
10+
public:
11+
static int run(const std::vector<std::string> &args);
12+
static int help();
13+
};
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
*
3+
* @file TaskCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_TASK_COMMAND_HPP
14+
#define VIX_TASK_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
class TaskCommand
22+
{
23+
public:
24+
static int run(const std::vector<std::string> &args);
25+
static int help();
26+
};
27+
}
28+
29+
#endif

src/CLI.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#include <vix/cli/commands/MakeCommand.hpp>
4545
#include <vix/cli/commands/CompletionCommand.hpp>
4646
#include <vix/cli/commands/InfoCommand.hpp>
47+
#include <vix/cli/commands/FmtCommand.hpp>
48+
#include <vix/cli/commands/CleanCommand.hpp>
49+
#include <vix/cli/commands/ResetCommand.hpp>
50+
#include <vix/cli/commands/TaskCommand.hpp>
4751
#include <vix/utils/Env.hpp>
4852
#include <vix/cli/Style.hpp>
4953
#include <vix/utils/Logger.hpp>
@@ -217,6 +221,14 @@ namespace vix
217221
{ return commands::CacheCommand::run(args); };
218222
commands_["info"] = [](auto args)
219223
{ return commands::InfoCommand::run(args); };
224+
commands_["fmt"] = [](auto args)
225+
{ return commands::FmtCommand::run(args); };
226+
commands_["clean"] = [](auto args)
227+
{ return commands::CleanCommand::run(args); };
228+
commands_["reset"] = [](auto args)
229+
{ return commands::ResetCommand::run(args); };
230+
commands_["task"] = [](auto args)
231+
{ return commands::TaskCommand::run(args); };
220232

221233
commands_["-h"] = [this](auto args)
222234
{ return help(args); };
@@ -456,6 +468,14 @@ namespace vix
456468
return commands::PublishCommand::help();
457469
if (cmd == "completion")
458470
return commands::CompletionCommand::help();
471+
if (cmd == "fmt")
472+
return commands::FmtCommand::help();
473+
if (cmd == "clean")
474+
return commands::CleanCommand::help();
475+
if (cmd == "reset")
476+
return commands::ResetCommand::help();
477+
if (cmd == "task")
478+
return commands::TaskCommand::help();
459479
if (cmd == "deps")
460480
{
461481
vix::cli::util::warn_line(std::cout, "'vix deps' is deprecated, use 'vix install'");
@@ -526,6 +546,10 @@ namespace vix
526546
out << indent(3) << "build Build project\n";
527547
out << indent(3) << "check Validate build or file\n";
528548
out << indent(3) << "tests Run tests\n";
549+
out << indent(3) << "fmt Format source code\n";
550+
out << indent(3) << "clean Remove project cache\n";
551+
out << indent(3) << "reset Clean and reinstall project\n";
552+
out << indent(3) << "task Run reusable project tasks\n";
529553
out << indent(3) << "repl Interactive REPL\n\n";
530554

531555
// Dependencies

src/commands/CleanCommand.cpp

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

src/commands/Dispatch.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include <vix/cli/util/Ui.hpp>
4444
#include <vix/cli/commands/CompletionCommand.hpp>
4545
#include <vix/cli/commands/InfoCommand.hpp>
46+
#include <vix/cli/commands/FmtCommand.hpp>
47+
#include <vix/cli/commands/CleanCommand.hpp>
48+
#include <vix/cli/commands/ResetCommand.hpp>
49+
#include <vix/cli/commands/TaskCommand.hpp>
4650

4751
#include <stdexcept>
4852

@@ -144,6 +148,38 @@ namespace vix::cli::dispatch
144148
[]()
145149
{ return vix::commands::OrmCommand::help(); }});
146150

151+
add({"fmt",
152+
"Project",
153+
"Format C++ source files",
154+
[](const Args &a)
155+
{ return vix::commands::FmtCommand::run(a); },
156+
[]()
157+
{ return vix::commands::FmtCommand::help(); }});
158+
159+
add({"clean",
160+
"Project",
161+
"Remove local cache directories",
162+
[](const Args &a)
163+
{ return vix::commands::CleanCommand::run(a); },
164+
[]()
165+
{ return vix::commands::CleanCommand::help(); }});
166+
167+
add({"reset",
168+
"Project",
169+
"Clean project cache and reinstall dependencies",
170+
[](const Args &a)
171+
{ return vix::commands::ResetCommand::run(a); },
172+
[]()
173+
{ return vix::commands::ResetCommand::help(); }});
174+
175+
add({"task",
176+
"Project",
177+
"Run reusable project tasks",
178+
[](const Args &a)
179+
{ return vix::commands::TaskCommand::run(a); },
180+
[]()
181+
{ return vix::commands::TaskCommand::help(); }});
182+
147183
// Packaging & security
148184
add({"pack",
149185
"Packaging",

0 commit comments

Comments
 (0)