Skip to content

Commit 795dda6

Browse files
committed
refactor(cli): add dedicated output renderer for new command
1 parent b792d6d commit 795dda6

5 files changed

Lines changed: 281 additions & 131 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file NewOutput.hpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license
8+
* that can be found in the License file.
9+
*
10+
* Minimal post-creation output for `vix new`:
11+
* banner line + thin rule + inline next steps.
12+
* Nothing else.
13+
*/
14+
15+
#ifndef VIX_CLI_NEW_OUTPUT_HPP
16+
#define VIX_CLI_NEW_OUTPUT_HPP
17+
18+
#include <filesystem>
19+
#include <string>
20+
#include <vector>
21+
22+
#include <vix/cli/commands/new/NewTypes.hpp>
23+
24+
namespace vix::commands::new_cmd::output
25+
{
26+
27+
/// "✔ <name> — <kind>"
28+
void print_banner(const std::string &projName, const std::string &kind);
29+
30+
/// Full creation summary for an Application project.
31+
void print_creation_app(
32+
const std::filesystem::path &projectDir,
33+
const std::string &projName,
34+
const FeaturesSelection &features);
35+
36+
/// Full creation summary for a Library project.
37+
void print_creation_lib(
38+
const std::filesystem::path &projectDir,
39+
const std::string &projName);
40+
41+
} // namespace vix::commands::new_cmd::output
42+
43+
#endif

src/CLI.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,6 @@ namespace vix
521521
out << "Fast. Simple. Built for real apps.\n";
522522
out << "Version: " << VIX_CLI_VERSION << "\n\n";
523523

524-
out << indent(1) << "Start in seconds:\n";
525-
out << indent(2) << "vix new api\n";
526-
out << indent(2) << "cd api\n";
527-
out << indent(2) << "vix install\n";
528-
out << indent(2) << "vix dev\n\n";
529-
530524
out << indent(1) << "Core workflow:\n";
531525
out << indent(2) << "add Add a dependency\n";
532526
out << indent(2) << "install Install project dependencies\n";

src/commands/new/NewGenerator.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
#include <vix/cli/commands/new/NewGenerator.hpp>
12+
#include <vix/cli/commands/new/NewOutput.hpp>
1213
#include <vix/cli/commands/new/NewTemplates.hpp>
13-
#include <vix/cli/util/Ui.hpp>
1414

1515
#include <filesystem>
1616
#include <fstream>
@@ -19,10 +19,9 @@
1919

2020
namespace vix::commands::new_cmd::generator
2121
{
22-
2322
namespace fs = std::filesystem;
2423
namespace tpl = vix::commands::new_cmd::templates;
25-
namespace ui = vix::cli::util;
24+
namespace out = vix::commands::new_cmd::output;
2625

2726
// ------------------------------------------------------------------
2827
// File-system helpers
@@ -215,29 +214,15 @@ namespace vix::commands::new_cmd::generator
215214
// Post-generation output
216215
// ------------------------------------------------------------------
217216

218-
void print_next_steps_app(const fs::path & /*projectDir*/, const std::string &projName)
217+
void print_next_steps_app(const fs::path &projectDir, const std::string &projName)
219218
{
220-
const std::string manifest = projName + ".vix";
221-
222-
std::cout << "\n";
223-
ui::info_line(std::cout, "Next steps");
224-
std::cout << " " << ui::dim("cd " + projName + "/") << "\n";
225-
std::cout << " " << ui::dim("vix build") << "\n";
226-
std::cout << " " << ui::dim("vix run") << "\n";
227-
std::cout << "\n";
228-
std::cout << " " << ui::dim("vix task dev") << "\n";
229-
std::cout << " " << ui::dim("vix dev " + manifest) << "\n";
219+
FeaturesSelection features{};
220+
out::print_creation_app(projectDir, projName, features);
230221
}
231222

232-
void print_next_steps_lib(const fs::path & /*projectDir*/, const std::string &projName)
223+
void print_next_steps_lib(const fs::path &projectDir, const std::string &projName)
233224
{
234-
std::cout << "\n";
235-
ui::info_line(std::cout, "Next steps");
236-
std::cout << " " << ui::dim("cd " + projName + "/") << "\n";
237-
std::cout << " " << ui::dim("vix build") << "\n";
238-
std::cout << " " << ui::dim("vix tests") << "\n";
239-
std::cout << "\n";
240-
std::cout << " " << ui::dim("TIP: tag + publish when ready") << "\n";
225+
out::print_creation_lib(projectDir, projName);
241226
}
242227

243228
} // namespace vix::commands::new_cmd::generator

src/commands/new/NewOutput.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* @file NewOutput.cpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license
8+
* that can be found in the License file.
9+
*/
10+
11+
#include <vix/cli/commands/new/NewOutput.hpp>
12+
#include <vix/cli/Style.hpp>
13+
14+
#include <iostream>
15+
#include <string>
16+
#include <vector>
17+
18+
using namespace vix::cli::style;
19+
20+
namespace vix::commands::new_cmd::output
21+
{
22+
23+
// ------------------------------------------------------------------
24+
// Internal
25+
// ------------------------------------------------------------------
26+
27+
static constexpr const char *TEAL = "\033[38;5;35m";
28+
29+
static void sep()
30+
{
31+
std::cout << PAD << GRAY << "─────────────────────────────────────" << RESET << "\n";
32+
}
33+
34+
static void section(const std::string &title)
35+
{
36+
std::cout << PAD << GRAY << title << RESET << "\n";
37+
}
38+
39+
static void print_command_step(int index, const std::string &cmd, const std::string &hint = "")
40+
{
41+
std::cout << PAD
42+
<< GRAY << index << RESET
43+
<< " "
44+
<< CYAN << BOLD << cmd << RESET;
45+
46+
if (!hint.empty())
47+
std::cout << " " << GRAY << hint << RESET;
48+
49+
std::cout << "\n";
50+
}
51+
52+
// ------------------------------------------------------------------
53+
// Banner
54+
// ------------------------------------------------------------------
55+
56+
void print_banner(const std::string &projName, const std::string &kind)
57+
{
58+
std::cout << "\n"
59+
<< PAD << TEAL << BOLD << "" << RESET
60+
<< " " << TEAL << BOLD << projName << RESET
61+
<< " " << GRAY << kind << RESET
62+
<< "\n";
63+
}
64+
65+
// ------------------------------------------------------------------
66+
// Next steps
67+
// ------------------------------------------------------------------
68+
69+
static void print_steps_app(const std::string &projName)
70+
{
71+
section("next");
72+
73+
print_command_step(1, "cd " + projName + "/", "enter project");
74+
print_command_step(2, "vix build", "compile");
75+
print_command_step(3, "vix run", "start app");
76+
77+
std::cout << "\n";
78+
}
79+
80+
static void print_steps_lib(const std::string &projName)
81+
{
82+
section("next");
83+
84+
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";
89+
}
90+
91+
// ------------------------------------------------------------------
92+
// High-level entry points
93+
// ------------------------------------------------------------------
94+
95+
void print_creation_app(
96+
const std::filesystem::path & /*projectDir*/,
97+
const std::string &projName,
98+
const FeaturesSelection & /*features*/)
99+
{
100+
print_banner(projName, "application");
101+
sep();
102+
print_steps_app(projName);
103+
}
104+
105+
void print_creation_lib(
106+
const std::filesystem::path & /*projectDir*/,
107+
const std::string &projName)
108+
{
109+
print_banner(projName, "library");
110+
sep();
111+
print_steps_lib(projName);
112+
}
113+
114+
} // namespace vix::commands::new_cmd::output

0 commit comments

Comments
 (0)