Skip to content

Commit 576e64e

Browse files
committed
feat(make): add config generator with interactive prompts
2 parents 83f5fa3 + d583290 commit 576e64e

6 files changed

Lines changed: 459 additions & 3 deletions

File tree

include/vix/cli/commands/make/MakeOptions.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ namespace vix::cli::make
3737
bool with_virtual_destructor = true;
3838
};
3939

40+
struct MakeConfigOptions
41+
{
42+
bool with_server = true;
43+
bool with_logging = true;
44+
bool with_waf = true;
45+
bool with_websocket = false;
46+
bool with_database = false;
47+
};
48+
4049
struct MakeOptions
4150
{
4251
std::string kind;
@@ -52,6 +61,7 @@ namespace vix::cli::make
5261
bool show_help = false;
5362

5463
MakeClassOptions class_options;
64+
MakeConfigOptions config_options;
5565
};
5666
} // namespace vix::cli::make
5767

include/vix/cli/commands/make/MakeTypes.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ namespace vix::cli::make
2929
Concept,
3030
Exception,
3131
Test,
32-
Module
32+
Module,
33+
Config
3334
};
3435

3536
[[nodiscard]] constexpr std::string_view to_string(const MakeKind kind) noexcept
@@ -54,6 +55,8 @@ namespace vix::cli::make
5455
return "test";
5556
case MakeKind::Module:
5657
return "module";
58+
case MakeKind::Config:
59+
return "config"; // ✅ AJOUT ICI
5760
case MakeKind::Unknown:
5861
default:
5962
return "unknown";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
*
3+
* @file ConfigGenerator.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+
*/
14+
#ifndef VIX_CONFIG_GENERATOR_HPP
15+
#define VIX_CONFIG_GENERATOR_HPP
16+
17+
#include <vix/cli/commands/make/MakeDispatcher.hpp>
18+
#include <vix/cli/commands/make/MakeResult.hpp>
19+
20+
namespace vix::cli::make::generators
21+
{
22+
struct ConfigSpec
23+
{
24+
bool with_server{true};
25+
bool with_logging{true};
26+
bool with_waf{true};
27+
bool with_websocket{false};
28+
bool with_database{false};
29+
};
30+
31+
[[nodiscard]] MakeResult generate_config(const MakeContext &ctx);
32+
33+
[[nodiscard]] MakeResult generate_config(const MakeContext &ctx,
34+
const ConfigSpec &spec);
35+
} // namespace vix::cli::make::generators
36+
37+
#endif

src/commands/MakeCommand.cpp

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,46 @@ namespace vix::commands
123123
{
124124
opt.header_only = true;
125125
}
126+
else if (a == "--server")
127+
{
128+
opt.config_options.with_server = true;
129+
}
130+
else if (a == "--no-server")
131+
{
132+
opt.config_options.with_server = false;
133+
}
134+
else if (a == "--logging")
135+
{
136+
opt.config_options.with_logging = true;
137+
}
138+
else if (a == "--no-logging")
139+
{
140+
opt.config_options.with_logging = false;
141+
}
142+
else if (a == "--waf")
143+
{
144+
opt.config_options.with_waf = true;
145+
}
146+
else if (a == "--no-waf")
147+
{
148+
opt.config_options.with_waf = false;
149+
}
150+
else if (a == "--websocket")
151+
{
152+
opt.config_options.with_websocket = true;
153+
}
154+
else if (a == "--no-websocket")
155+
{
156+
opt.config_options.with_websocket = false;
157+
}
158+
else if (a == "--database")
159+
{
160+
opt.config_options.with_database = true;
161+
}
162+
else if (a == "--no-database")
163+
{
164+
opt.config_options.with_database = false;
165+
}
126166
else if (a == "-d" || a == "--dir")
127167
{
128168
if (i + 1 < args.size() && !is_option_token(args[i + 1]))
@@ -458,6 +498,59 @@ namespace vix::commands
458498
return run_direct(opt);
459499
}
460500

501+
int run_config_prompt(mk::MakeOptions opt)
502+
{
503+
if (opt.name.empty())
504+
{
505+
while (true)
506+
{
507+
opt.name = prompt_line("Config name: ");
508+
509+
if (opt.name.empty())
510+
{
511+
ui::warn_line(std::cout, "Config name is required.");
512+
continue;
513+
}
514+
515+
if (!mk::is_valid_cpp_identifier(opt.name))
516+
{
517+
ui::warn_line(std::cout, "Invalid config name.");
518+
continue;
519+
}
520+
521+
if (mk::is_reserved_cpp_keyword(opt.name))
522+
{
523+
ui::warn_line(std::cout, "Reserved C++ keyword is not allowed.");
524+
continue;
525+
}
526+
527+
break;
528+
}
529+
}
530+
531+
opt.config_options.with_server =
532+
prompt_yes_no("Include server section?", opt.config_options.with_server);
533+
534+
opt.config_options.with_logging =
535+
prompt_yes_no("Include logging section?", opt.config_options.with_logging);
536+
537+
opt.config_options.with_waf =
538+
prompt_yes_no("Include waf section?", opt.config_options.with_waf);
539+
540+
opt.config_options.with_websocket =
541+
prompt_yes_no("Include websocket section?", opt.config_options.with_websocket);
542+
543+
opt.config_options.with_database =
544+
prompt_yes_no("Include database section?", opt.config_options.with_database);
545+
546+
if (opt.in.empty())
547+
{
548+
opt.in = prompt_line("Target folder (optional): ");
549+
}
550+
551+
return run_direct(opt);
552+
}
553+
461554
int run_interactive(mk::MakeOptions opt)
462555
{
463556
const mk::MakeKind kind = mk::parse_make_kind(opt.kind);
@@ -467,6 +560,9 @@ namespace vix::commands
467560
case mk::MakeKind::Class:
468561
return run_class_prompt(opt);
469562

563+
case mk::MakeKind::Config:
564+
return run_config_prompt(opt);
565+
470566
case mk::MakeKind::Struct:
471567
case mk::MakeKind::Enum:
472568
case mk::MakeKind::Function:
@@ -534,7 +630,8 @@ namespace vix::commands
534630
out << " concept Generate a C++20 concept (.hpp)\n";
535631
out << " exception Generate a std::exception derived type\n";
536632
out << " test Generate a GoogleTest skeleton\n";
537-
out << " module Redirects to the modules workflow\n\n";
633+
out << " module Redirects to the modules workflow\n";
634+
out << " config Generate a JSON runtime configuration file\n\n";
538635

539636
out << "Options:\n";
540637
out << " -d, --dir <path> Project root (default: current directory)\n";
@@ -544,6 +641,16 @@ namespace vix::commands
544641
out << " --print Print preview/snippet without writing files\n";
545642
out << " --dry-run Show what would be generated without writing files\n";
546643
out << " --force Overwrite existing files\n";
644+
out << " --server Enable server section for config generation\n";
645+
out << " --no-server Disable server section for config generation\n";
646+
out << " --logging Enable logging section for config generation\n";
647+
out << " --no-logging Disable logging section for config generation\n";
648+
out << " --waf Enable waf section for config generation\n";
649+
out << " --no-waf Disable waf section for config generation\n";
650+
out << " --websocket Enable websocket section for config generation\n";
651+
out << " --no-websocket Disable websocket section for config generation\n";
652+
out << " --database Enable database section for config generation\n";
653+
out << " --no-database Disable database section for config generation\n";
547654
out << " -h, --help Show help\n\n";
548655

549656
out << "Examples:\n";
@@ -556,7 +663,10 @@ namespace vix::commands
556663
out << " vix make lambda visit_all --print\n";
557664
out << " vix make concept EqualityComparable\n";
558665
out << " vix make exception InvalidToken --in src/auth\n";
559-
out << " vix make test AuthService\n\n";
666+
out << " vix make test AuthService\n";
667+
out << " vix make config app\n";
668+
out << " vix make config app --websocket --database\n";
669+
out << " vix make:config\n\n";
560670

561671
out << "Behavior:\n";
562672
out << " - By default, files are generated in the current directory.\n";

src/commands/make/MakeDispatcher.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <vix/cli/commands/make/generators/ConceptGenerator.hpp>
2222
#include <vix/cli/commands/make/generators/ExceptionGenerator.hpp>
2323
#include <vix/cli/commands/make/generators/TestGenerator.hpp>
24+
#include <vix/cli/commands/make/generators/ConfigGenerator.hpp>
2425

2526
#include <utility>
2627

@@ -187,6 +188,11 @@ namespace vix::cli::make
187188
return generators::generate_test(ctx);
188189
}
189190

191+
[[nodiscard]] MakeResult dispatch_config(const MakeContext &ctx)
192+
{
193+
return generators::generate_config(ctx);
194+
}
195+
190196
[[nodiscard]] MakeResult dispatch_module(const MakeContext &ctx)
191197
{
192198
MakeResult result;
@@ -219,6 +225,8 @@ namespace vix::cli::make
219225
return MakeKind::Test;
220226
if (k == "module")
221227
return MakeKind::Module;
228+
if (k == "config")
229+
return MakeKind::Config;
222230

223231
return MakeKind::Unknown;
224232
}
@@ -267,6 +275,9 @@ namespace vix::cli::make
267275
case MakeKind::Module:
268276
return dispatch_module(ctx);
269277

278+
case MakeKind::Config:
279+
return dispatch_config(ctx);
280+
270281
case MakeKind::Unknown:
271282
default:
272283
return make_error("Unknown make kind.");

0 commit comments

Comments
 (0)