Skip to content

Commit a630b62

Browse files
committed
cli(run): expose docs toggle via VIX_DOCS (--docs, --no-docs)
1 parent f0cb00d commit a630b62

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace vix::commands::RunCommand::detail
7474
std::string cwd;
7575
bool badDoubleDashRuntimeArgs = false;
7676
std::string badDoubleDashArg;
77+
std::optional<bool> docs;
7778
};
7879

7980
struct ScriptRunResult

src/commands/RunCommand.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ namespace vix::commands::RunCommand
253253
#endif
254254
}
255255

256+
static void apply_docs_env(const Options &opt)
257+
{
258+
if (!opt.docs.has_value())
259+
return;
260+
261+
#ifdef _WIN32
262+
_putenv_s("VIX_DOCS", (*opt.docs ? "1" : "0"));
263+
#else
264+
::setenv("VIX_DOCS", (*opt.docs ? "1" : "0"), 1);
265+
#endif
266+
}
267+
256268
int run(const std::vector<std::string> &args)
257269
{
258270
Options opt = parse(args);
@@ -286,6 +298,7 @@ namespace vix::commands::RunCommand
286298

287299
apply_log_env(opt);
288300
vix::cli::manifest::apply_env_pairs(opt.runEnv);
301+
apply_docs_env(opt);
289302

290303
#ifndef _WIN32
291304
::setenv("VIX_CLI_CLEAR", opt.clearMode.c_str(), 1);
@@ -976,20 +989,25 @@ namespace vix::commands::RunCommand
976989

977990
out << "Runtime options:\n";
978991
out << " --cwd <path> Run the program with this working directory\n";
979-
out << " --env <K=V> Add/override one environment variable (repeatable)\n";
992+
out << " --env <K=V> Add or override one environment variable (repeatable)\n";
980993
out << " --args <value> Add one runtime argument (repeatable)\n\n";
981994

982995
out << "Watch / reload:\n";
983-
out << " --watch, --reload Rebuild & restart on file changes\n";
996+
out << " --watch, --reload Rebuild and restart on file changes\n";
984997
out << " --force-server Treat process as long-lived (server-like)\n";
985998
out << " --force-script Treat process as short-lived (script-like)\n\n";
986999

9871000
out << "Script mode (single .cpp) flags:\n";
988-
out << " --san Enable ASan + UBSan\n";
1001+
out << " --san Enable ASan and UBSan\n";
9891002
out << " --ubsan Enable UBSan only\n\n";
9901003

1004+
out << "Documentation (OpenAPI / Swagger):\n";
1005+
out << " --docs Enable auto docs (sets VIX_DOCS=1)\n";
1006+
out << " --no-docs Disable auto docs (sets VIX_DOCS=0)\n";
1007+
out << " --docs=<0|1|true|false> Explicitly control docs generation\n\n";
1008+
9911009
out << "Logging:\n";
992-
out << " --log-level <level> debug | info | warn | error\n";
1010+
out << " --log-level <level> trace | debug | info | warn | error | critical | off\n";
9931011
out << " --verbose Alias for --log-level=debug\n";
9941012
out << " -q, --quiet Alias for --log-level=warn\n";
9951013
out << " --log-format <kv|json|json-pretty>\n";
@@ -1016,6 +1034,9 @@ namespace vix::commands::RunCommand
10161034
out << " vix run main.cpp -- -L/usr/lib -lssl\n";
10171035
out << " vix run main.cpp -- -DDEBUG\n\n";
10181036

1037+
out << " # Disable auto docs\n";
1038+
out << " vix run api.cpp --no-docs\n\n";
1039+
10191040
out << " # Manifest mode (.vix)\n";
10201041
out << " vix run api.vix\n";
10211042
out << " vix run api.vix --args --port --args 8080\n";
@@ -1034,6 +1055,7 @@ namespace vix::commands::RunCommand
10341055
out << " vix run example now_server\n\n";
10351056

10361057
out << "Environment:\n";
1058+
out << " VIX_DOCS 0|1 Enable or disable auto docs\n";
10371059
out << " VIX_LOG_LEVEL trace|debug|info|warn|error|critical|off\n";
10381060
out << " VIX_LOG_FORMAT kv|json|json-pretty\n";
10391061
out << " VIX_COLOR auto|always|never (NO_COLOR disables colors)\n";

src/commands/run/RunFlow.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ namespace vix::commands::RunCommand::detail
6565
return std::nullopt;
6666
}
6767

68+
static std::string lower(std::string s)
69+
{
70+
for (auto &c : s)
71+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
72+
return s;
73+
}
74+
6875
std::filesystem::path manifest_entry_cpp(const std::filesystem::path &manifestFile)
6976
{
7077
namespace fs = std::filesystem;
@@ -259,6 +266,24 @@ namespace vix::commands::RunCommand::detail
259266
{
260267
o.forceScriptLike = true;
261268
}
269+
else if (a == "--docs")
270+
{
271+
o.docs = true;
272+
}
273+
else if (a == "--no-docs")
274+
{
275+
o.docs = false;
276+
}
277+
else if (a.rfind("--docs=", 0) == 0)
278+
{
279+
std::string v = lower(a.substr(std::string("--docs=").size()));
280+
if (v == "1" || v == "true" || v == "yes" || v == "on")
281+
o.docs = true;
282+
else if (v == "0" || v == "false" || v == "no" || v == "off")
283+
o.docs = false;
284+
else
285+
hint("Invalid value for --docs. Use 0|1|true|false.");
286+
}
262287
else if (a == "--cwd" && i + 1 < args.size())
263288
{
264289
std::filesystem::path p = args[++i];
@@ -772,13 +797,6 @@ namespace vix::commands::RunCommand::detail
772797
return cwd;
773798
}
774799

775-
static std::string lower(std::string s)
776-
{
777-
for (auto &c : s)
778-
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
779-
return s;
780-
}
781-
782800
void apply_log_level_env(const Options &opt)
783801
{
784802
std::string level;

0 commit comments

Comments
 (0)