Skip to content

Commit 39fcd76

Browse files
committed
repl: forward CLI args to REPL and expose them via Vix.args()
1 parent d655ebf commit 39fcd76

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

include/vix/cli/commands/repl/ReplFlow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace vix::commands::ReplCommand
1717
{
18-
int repl_flow_run();
18+
int repl_flow_run(const std::vector<std::string> &replArgs);
1919
}
2020

2121
#endif

src/commands/ReplCommand.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,28 @@ namespace vix::commands::ReplCommand
2020
{
2121
int run(const std::vector<std::string> &args)
2222
{
23-
(void)args;
24-
return repl_flow_run();
23+
std::vector<std::string> replArgs = args;
24+
if (!replArgs.empty() && replArgs[0] == "--")
25+
replArgs.erase(replArgs.begin());
26+
27+
return repl_flow_run(replArgs);
2528
}
2629

2730
int help()
2831
{
2932
std::cout
3033
<< "Usage:\n"
31-
<< " vix repl\n\n"
34+
<< " vix repl [-- <args...>]\n\n"
3235
<< "Description:\n"
33-
<< " Start an interactive Vix REPL (CLI shell + calculator).\n\n"
36+
<< " Start an interactive Vix REPL (shell + calculator).\n"
37+
<< " Args after `--` are available via Vix.args().\n\n"
3438
<< "Examples:\n"
3539
<< " vix repl\n"
36-
<< " vix repl # then: = 1+2*3\n";
40+
<< " vix repl -- --port 8080 --mode dev\n"
41+
<< " # inside REPL:\n"
42+
<< " # Vix.args()\n"
43+
<< " # x = 1+2*3\n";
3744
return 0;
3845
}
46+
3947
}

src/commands/repl/ReplFlow.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,19 @@ namespace
446446

447447
if (m == "args")
448448
{
449-
// print JSON array
449+
// args() takes no parameters in REPL (getter only)
450+
if (!call.args.empty())
451+
{
452+
vix::cli::repl::api::println(
453+
"error: Vix.args() takes no arguments.\n"
454+
"hint: use Vix.args() to read CLI args.");
455+
return true;
456+
}
457+
450458
nlohmann::json j = nlohmann::json::array();
451459
for (const auto &a : VixObj.args())
452460
j.push_back(a);
461+
453462
vix::cli::repl::api::println(j.dump());
454463
return true;
455464
}
@@ -639,7 +648,7 @@ namespace
639648

640649
namespace vix::commands::ReplCommand
641650
{
642-
int repl_flow_run()
651+
int repl_flow_run(const std::vector<std::string> &replArgs)
643652
{
644653
using vix::cli::repl::History;
645654
using vix::cli::repl::ReplConfig;
@@ -654,7 +663,7 @@ namespace vix::commands::ReplCommand
654663
vix::cli::repl::api::Vix VixObj(&history);
655664
std::unordered_map<std::string, nlohmann::json> vars;
656665

657-
VixObj.set_args({});
666+
VixObj.set_args(replArgs);
658667

659668
if (cfg.enableFileHistory)
660669
{

0 commit comments

Comments
 (0)