Skip to content

Commit 1c4f5f1

Browse files
committed
Polish modules command output
2 parents 4a6ab34 + 2ca123d commit 1c4f5f1

6 files changed

Lines changed: 162 additions & 28 deletions

File tree

src/commands/ModulesCommand.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ namespace vix::commands::ModulesCommand
113113

114114
if (opt.subcmd == "init")
115115
{
116-
ui::section(std::cout, "Modules");
117116
return cmds::cmd_init(root, opt.patchRoot) ? 0 : 1;
118117
}
119118

@@ -125,13 +124,12 @@ namespace vix::commands::ModulesCommand
125124
ui::warn_line(std::cout, "Usage: vix modules add <name>");
126125
return 1;
127126
}
128-
ui::section(std::cout, "Modules");
127+
129128
return cmds::cmd_add(root, project, opt.module, opt.patchLink) ? 0 : 1;
130129
}
131130

132131
if (opt.subcmd == "check")
133132
{
134-
ui::section(std::cout, "Modules");
135133
return cmds::cmd_check(root, project) ? 0 : 1;
136134
}
137135

src/commands/NewCommand.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ namespace vix::commands::NewCommand
349349
<< " • Generates a ready-to-run Vix project\n"
350350
<< " • Sets up CMake, source structure, and config files\n"
351351
<< " • Creates a vix.json manifest\n"
352-
<< " • For apps, includes default tasks and an empty deps list\n"
353-
<< " • For libraries, includes package metadata and an empty deps list\n"
352+
<< " • For apps, creates an executable target matching the project name\n"
353+
<< " • For libraries, creates a header-only CMake interface target\n"
354354
<< " • Applies the selected template (app or library)\n\n"
355355

356356
<< "Options\n"
@@ -359,6 +359,17 @@ namespace vix::commands::NewCommand
359359
<< " -d, --dir Base directory for project creation\n"
360360
<< " --force Overwrite existing directory\n\n"
361361

362+
<< "Application workflow\n"
363+
<< " cd api/\n"
364+
<< " vix build\n"
365+
<< " vix run\n\n"
366+
367+
<< "Library workflow\n"
368+
<< " cd tree/\n"
369+
<< " vix build --build-target all\n"
370+
<< " vix build --build-target all -- -Dtree_BUILD_TESTS=ON\n"
371+
<< " vix tests\n\n"
372+
362373
<< "Environment\n"
363374
<< " VIX_NONINTERACTIVE=1 Disable prompts\n"
364375
<< " CI=1 Disable prompts\n\n"
@@ -368,6 +379,8 @@ namespace vix::commands::NewCommand
368379
<< " • Use 'vix add <pkg>' to add dependencies\n"
369380
<< " • Use 'vix install' to install from vix.lock\n"
370381
<< " • Use 'vix task <name>' to run generated tasks\n"
382+
<< " • For header-only libraries, use '--build-target all' to build the generated project\n"
383+
<< " • Tests for header-only libraries are disabled by default and must be enabled with CMake args\n"
371384
<< " • Designed for fast start with zero setup\n";
372385

373386
return 0;

src/commands/modules/ModulesCommands.cpp

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,44 @@ namespace vix::commands::modules_cmd::commands
2828
namespace ui = vix::cli::util;
2929
using namespace vix::cli::style;
3030

31+
static constexpr const char *TEAL = "\033[38;5;35m";
32+
33+
static void sep()
34+
{
35+
std::cout << PAD << GRAY << "─────────────────────────────────────" << RESET << "\n";
36+
}
37+
38+
static void section(const std::string &title)
39+
{
40+
std::cout << PAD << GRAY << title << RESET << "\n";
41+
}
42+
43+
static void print_command_step(
44+
int index,
45+
const std::string &cmd,
46+
const std::string &hint = "")
47+
{
48+
std::cout << PAD
49+
<< GRAY << index << RESET
50+
<< " "
51+
<< CYAN << BOLD << cmd << RESET;
52+
53+
if (!hint.empty())
54+
std::cout << " " << GRAY << hint << RESET;
55+
56+
std::cout << "\n";
57+
}
58+
59+
static void print_modules_banner(
60+
const std::string &name,
61+
const std::string &kind)
62+
{
63+
std::cout << PAD << TEAL << BOLD << "" << RESET
64+
<< " " << TEAL << BOLD << name << RESET
65+
<< " " << GRAY << kind << RESET
66+
<< "\n";
67+
}
68+
3169
bool cmd_init(const fs::path &root, bool patchRoot)
3270
{
3371
const fs::path modulesDir = root / "modules";
@@ -58,12 +96,19 @@ namespace vix::commands::modules_cmd::commands
5896
return false;
5997
}
6098

61-
ui::ok_line(std::cout, "Modules mode initialized");
62-
ui::kv(std::cout, "modules", (root / "modules").string(), 10);
63-
ui::kv(std::cout, "cmake", (root / "cmake" / "vix_modules.cmake").string(), 10);
99+
print_modules_banner("modules", "initialized");
100+
sep();
101+
102+
section("files");
103+
print_command_step(1, "modules/", "module directory");
104+
print_command_step(2, "cmake/vix_modules.cmake", "module loader");
105+
64106
if (patchRoot)
65-
ui::kv(std::cout, "patch", "root CMakeLists.txt updated (idempotent markers)", 10);
66-
ui::warn_line(std::cout, "Next: vix modules add <name>");
107+
print_command_step(3, "CMakeLists.txt", "patched");
108+
109+
sep();
110+
section("next");
111+
print_command_step(1, "vix modules add <name>", "create module");
67112

68113
return true;
69114
}
@@ -148,20 +193,47 @@ namespace vix::commands::modules_cmd::commands
148193
return false;
149194
}
150195

151-
ui::ok_line(std::cout, "Module created");
152-
ui::kv(std::cout, "name", normalized, 10);
153-
ui::kv(std::cout, "target", cnt::module_alias_name(project, module), 10);
154-
ui::kv(std::cout, "public", "modules/" + normalized + "/include/" + normalized + "/api.hpp", 10);
155-
ui::kv(std::cout, "impl", "modules/" + normalized + "/src/" + normalized + ".cpp", 10);
196+
print_modules_banner(normalized, "module");
197+
sep();
198+
199+
section("files");
200+
print_command_step(
201+
1,
202+
"modules/" + normalized + "/include/" + normalized + "/api.hpp",
203+
"public header");
204+
205+
print_command_step(
206+
2,
207+
"modules/" + normalized + "/src/" + normalized + ".cpp",
208+
"implementation");
209+
210+
print_command_step(
211+
3,
212+
"modules/" + normalized + "/CMakeLists.txt",
213+
"target");
214+
215+
sep();
216+
section("target");
217+
print_command_step(1, cnt::module_alias_name(project, module), "CMake alias");
218+
219+
sep();
220+
section("next");
221+
print_command_step(
222+
1,
223+
"#include <" + normalized + "/api.hpp>",
224+
"include");
156225

157-
ui::warn_line(std::cout, "Next steps (CMake):");
158-
std::cout << " " << GRAY << "" << RESET
159-
<< "Include: " << YELLOW << BOLD << "#include <" << normalized << "/api.hpp>" << RESET << "\n";
160226
if (patchRootLink)
161-
std::cout << " " << GRAY << "" << RESET
162-
<< "Root: " << GRAY
163-
<< "(auto-linked if main target is named like project(" << project << "))"
164-
<< RESET << "\n";
227+
{
228+
print_command_step(2, "vix build", "compile");
229+
}
230+
else
231+
{
232+
print_command_step(
233+
2,
234+
"target_link_libraries(" + project + " PRIVATE " + cnt::module_alias_name(project, module) + ")",
235+
"link manually");
236+
}
165237

166238
return true;
167239
}

src/commands/new/NewOutput.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ namespace vix::commands::new_cmd::output
7373
print_command_step(1, "cd " + projName + "/", "enter project");
7474
print_command_step(2, "vix build", "compile");
7575
print_command_step(3, "vix run", "start app");
76-
77-
std::cout << "\n";
7876
}
7977

8078
static void print_steps_lib(const std::string &projName)
8179
{
8280
section("next");
8381

8482
print_command_step(1, "cd " + projName + "/", "enter project");
85-
print_command_step(2, "vix build", "compile");
86-
print_command_step(3, "vix tests", "run tests");
87-
88-
std::cout << "\n";
83+
print_command_step(2, "vix build --build-target all", "compile");
84+
print_command_step(
85+
3,
86+
"vix build --build-target all -- -D" + projName + "_BUILD_TESTS=ON",
87+
"enable tests");
88+
print_command_step(4, "vix tests", "run tests");
8989
}
9090

9191
// ------------------------------------------------------------------

src/commands/new/NewTemplates.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ namespace vix::commands::new_cmd::templates
251251
readme += "```\n\n";
252252

253253
readme += "## Tests\n\n";
254+
readme += "Tests are disabled by default for header-only libraries.\n\n";
255+
readme += "Enable them first:\n\n";
256+
readme += "```bash\n";
257+
readme += "vix build --build-target all -- -D" + name + "_BUILD_TESTS=ON\n";
258+
readme += "```\n\n";
259+
readme += "Then run:\n\n";
254260
readme += "```bash\n";
255261
readme += "vix tests\n";
256262
readme += "```\n\n";

src/errors/build/CMakeBuildErrors.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,48 @@ namespace vix::cli::errors::build
4343
return {};
4444
}
4545

46+
static bool handle_unknown_ninja_target(std::string_view log)
47+
{
48+
constexpr std::string_view marker = "ninja: error: unknown target '";
49+
50+
const std::size_t pos = log.find(marker);
51+
52+
if (pos == std::string_view::npos)
53+
return false;
54+
55+
const std::size_t start = pos + marker.size();
56+
const std::size_t end = log.find('\'', start);
57+
58+
std::string target = "unknown";
59+
60+
if (end != std::string_view::npos && end > start)
61+
target = std::string(log.substr(start, end - start));
62+
63+
std::cerr << PAD
64+
<< RED << BOLD << "✖ Build target not found" << RESET
65+
<< "\n";
66+
67+
std::cerr << PAD
68+
<< CYAN << "target:" << RESET
69+
<< " "
70+
<< target
71+
<< "\n";
72+
73+
std::cerr << PAD
74+
<< YELLOW << "hint:" << RESET
75+
<< " "
76+
<< "This project does not define a CMake target named '"
77+
<< target
78+
<< "'.\n";
79+
80+
std::cerr << PAD
81+
<< " "
82+
<< "Check your CMakeLists.txt or use --build-target with an existing target."
83+
<< "\n";
84+
85+
return true;
86+
}
87+
4688
bool contains(std::string_view log, std::string_view needle)
4789
{
4890
return log.find(needle) != std::string_view::npos;
@@ -570,6 +612,9 @@ namespace vix::cli::errors::build
570612

571613
bool handleCMakeBuildError(std::string_view log)
572614
{
615+
if (handle_unknown_ninja_target(log))
616+
return true;
617+
573618
if (handleCacheMismatch(log))
574619
return true;
575620

0 commit comments

Comments
 (0)