Skip to content

Commit 180b5cd

Browse files
committed
fix(cli): correctly forward runtime arguments after target in vix run
- Fix positional argument parsing to prevent overriding appName - Ensure all arguments after the target are treated as runtime args - Enable proper support for commands like: vix run docker://nginx -p 8080:80 - Fix container execution by preserving image name and flags order - Improve CLI behavior to match modern runtimes (docker, npm, cargo)
1 parent af81e23 commit 180b5cd

3 files changed

Lines changed: 426 additions & 16 deletions

File tree

src/commands/BuildCommand.cpp

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,26 @@ namespace vix::commands::BuildCommand
10501050
return std::nullopt;
10511051
}
10521052

1053+
static void write_last_binary(const fs::path &path)
1054+
{
1055+
const fs::path metaDir = fs::current_path() / ".vix";
1056+
const fs::path metaFile = metaDir / "meta.json";
1057+
1058+
std::error_code ec;
1059+
fs::create_directories(metaDir, ec);
1060+
1061+
if (ec)
1062+
return;
1063+
1064+
std::ofstream out(metaFile);
1065+
if (!out)
1066+
return;
1067+
1068+
out << "{\n";
1069+
out << " \"last_binary\": \"" << path.string() << "\"\n";
1070+
out << "}\n";
1071+
}
1072+
10531073
static bool export_built_binary(
10541074
const fs::path &sourceExe,
10551075
const fs::path &destination,
@@ -1091,9 +1111,11 @@ namespace vix::commands::BuildCommand
10911111
if (!quiet)
10921112
success("Exported binary: " + finalDest.string());
10931113

1114+
// ✅ AJOUT ICI
1115+
write_last_binary(finalDest);
1116+
10941117
return true;
10951118
}
1096-
10971119
class BuildCommand
10981120
{
10991121
public:
@@ -1474,6 +1496,40 @@ namespace vix::commands::BuildCommand
14741496
process::Plan plan_{};
14751497
};
14761498

1499+
static std::optional<fs::path> find_last_built_binary()
1500+
{
1501+
namespace fs = std::filesystem;
1502+
1503+
const fs::path meta = fs::current_path() / ".vix" / "meta.json";
1504+
1505+
if (!fs::exists(meta))
1506+
return std::nullopt;
1507+
1508+
std::ifstream f(meta);
1509+
if (!f)
1510+
return std::nullopt;
1511+
1512+
std::string content((std::istreambuf_iterator<char>(f)),
1513+
std::istreambuf_iterator<char>());
1514+
1515+
const std::string key = "\"last_binary\":\"";
1516+
auto pos = content.find(key);
1517+
if (pos == std::string::npos)
1518+
return std::nullopt;
1519+
1520+
pos += key.size();
1521+
auto end = content.find("\"", pos);
1522+
if (end == std::string::npos)
1523+
return std::nullopt;
1524+
1525+
fs::path p = content.substr(pos, end - pos);
1526+
1527+
if (fs::exists(p))
1528+
return p;
1529+
1530+
return std::nullopt;
1531+
}
1532+
14771533
} // namespace
14781534

14791535
int run(const std::vector<std::string> &args)
@@ -1518,11 +1574,11 @@ namespace vix::commands::BuildCommand
15181574
return 1;
15191575
}
15201576

1577+
// Default behavior: if building a single file and no output option is provided,
1578+
// fallback to --bin automatically.
15211579
if (!opt_.exportBin && opt_.outPath.empty())
15221580
{
1523-
error("Single-file build requires --bin or --out <path>.");
1524-
hint("Example: vix build main.cpp --out app.exe");
1525-
return 2;
1581+
opt_.exportBin = true;
15261582
}
15271583

15281584
run_detail::Options runOpt{};

0 commit comments

Comments
 (0)