- Move ci-test.sh and setup.sh to scripts/ - Trim docs/src/zig-cli.md to current structure - Replace hardcoded secrets with placeholders in configs - Update .gitignore to block .env*, secrets/, keys, build artifacts - Slim README.md to reflect current CLI/TUI split - Add cleanup trap to ci-test.sh - Ensure no secrets are committed
52 lines
1.8 KiB
Zig
52 lines
1.8 KiB
Zig
const std = @import("std");
|
|
const Config = @import("../config.zig").Config;
|
|
|
|
pub fn run(allocator: std.mem.Allocator, args: []const []const u8) !void {
|
|
const config = try Config.load(allocator);
|
|
defer {
|
|
var mut_config = config;
|
|
mut_config.deinit(allocator);
|
|
}
|
|
|
|
std.debug.print("Launching TUI via SSH...\n", .{});
|
|
|
|
// Build remote command that exports config via env vars and runs the TUI
|
|
var remote_cmd_buffer = std.ArrayList(u8).init(allocator);
|
|
defer remote_cmd_buffer.deinit();
|
|
{
|
|
const writer = remote_cmd_buffer.writer();
|
|
try writer.print("cd {s} && ", .{config.worker_base});
|
|
try writer.print(
|
|
"FETCH_ML_CLI_HOST=\"{s}\" FETCH_ML_CLI_USER=\"{s}\" FETCH_ML_CLI_BASE=\"{s}\" ",
|
|
.{ config.worker_host, config.worker_user, config.worker_base },
|
|
);
|
|
try writer.print(
|
|
"FETCH_ML_CLI_PORT=\"{d}\" FETCH_ML_CLI_API_KEY=\"{s}\" ",
|
|
.{ config.worker_port, config.api_key },
|
|
);
|
|
try writer.writeAll("./bin/tui");
|
|
for (args) |arg| {
|
|
try writer.print(" {s}", .{arg});
|
|
}
|
|
}
|
|
const remote_cmd = try remote_cmd_buffer.toOwnedSlice();
|
|
defer allocator.free(remote_cmd);
|
|
|
|
const ssh_cmd = try std.fmt.allocPrint(
|
|
allocator,
|
|
"ssh -t -p {d} {s}@{s} '{s}'",
|
|
.{ config.worker_port, config.worker_user, config.worker_host, remote_cmd },
|
|
);
|
|
defer allocator.free(ssh_cmd);
|
|
|
|
var child = std.process.Child.init(&[_][]const u8{ "sh", "-c", ssh_cmd }, allocator);
|
|
child.stdin_behavior = .Inherit;
|
|
child.stdout_behavior = .Inherit;
|
|
child.stderr_behavior = .Inherit;
|
|
|
|
const term = try child.spawnAndWait();
|
|
|
|
if (term.tag == .Exited and term.Exited != 0) {
|
|
std.debug.print("TUI exited with code {d}\n", .{term.Exited});
|
|
}
|
|
}
|