Expose local socket protocol and mimctl basics
This commit is contained in:
+48
-5
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
const protocol = @import("protocol.zig");
|
||||
const session = @import("session.zig");
|
||||
const socket = @import("socket.zig");
|
||||
|
||||
pub const version = "0.1.0-dev";
|
||||
|
||||
@@ -9,9 +11,10 @@ const help_text =
|
||||
\\Usage:
|
||||
\\ mim [--help]
|
||||
\\ mim [--version]
|
||||
\\ mim --mimctl <socket> <request...>
|
||||
\\
|
||||
\\This skeleton intentionally starts with only the canonical smoke path.
|
||||
\\Future editor behavior is added through verified product slices.
|
||||
\\This early build exposes the canonical smoke path and a minimal local
|
||||
\\session-control client for trusted tools.
|
||||
\\
|
||||
;
|
||||
|
||||
@@ -36,18 +39,44 @@ fn versionText() []const u8 {
|
||||
}
|
||||
|
||||
pub fn main(init: std.process.Init) !u8 {
|
||||
var debug_allocator = std.heap.DebugAllocator(.{}){};
|
||||
defer _ = debug_allocator.deinit();
|
||||
const allocator = debug_allocator.allocator();
|
||||
|
||||
var args = std.process.Args.Iterator.init(init.minimal.args);
|
||||
_ = args.skip();
|
||||
|
||||
const stdout = std.Io.File.stdout();
|
||||
const stderr = std.Io.File.stderr();
|
||||
|
||||
const first_arg = args.next();
|
||||
if (first_arg) |arg| {
|
||||
if (std.mem.eql(u8, arg, "--mimctl")) {
|
||||
const socket_path = args.next() orelse {
|
||||
try stderr.writeStreamingAll(init.io, "mim: --mimctl requires a socket path\n");
|
||||
return 64;
|
||||
};
|
||||
const line = try collectRemainingArgs(allocator, &args);
|
||||
defer allocator.free(line);
|
||||
if (line.len == 0) {
|
||||
try stderr.writeStreamingAll(init.io, "mim: --mimctl requires a request\n");
|
||||
return 64;
|
||||
}
|
||||
const response = socket.request(allocator, socket_path, line) catch {
|
||||
try stderr.writeStreamingAll(init.io, "mim: mimctl request failed\n");
|
||||
return 69;
|
||||
};
|
||||
defer allocator.free(response);
|
||||
try stdout.writeStreamingAll(init.io, response);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const command = if (first_arg) |arg|
|
||||
parseArgs(&.{ "mim", arg })
|
||||
else
|
||||
parseArgs(&.{"mim"});
|
||||
|
||||
const stdout = std.Io.File.stdout();
|
||||
const stderr = std.Io.File.stderr();
|
||||
|
||||
switch (command) {
|
||||
.help => try stdout.writeStreamingAll(init.io, help_text),
|
||||
.version => try stdout.writeStreamingAll(init.io, versionText()),
|
||||
@@ -63,8 +92,22 @@ pub fn main(init: std.process.Init) !u8 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn collectRemainingArgs(allocator: std.mem.Allocator, args: *std.process.Args.Iterator) ![]u8 {
|
||||
var line = std.ArrayList(u8).empty;
|
||||
errdefer line.deinit(allocator);
|
||||
var first = true;
|
||||
while (args.next()) |arg| {
|
||||
if (!first) try line.append(allocator, ' ');
|
||||
try line.appendSlice(allocator, arg);
|
||||
first = false;
|
||||
}
|
||||
return line.toOwnedSlice(allocator);
|
||||
}
|
||||
|
||||
test {
|
||||
_ = protocol;
|
||||
_ = session;
|
||||
_ = socket;
|
||||
}
|
||||
|
||||
test "regular: help text names the binary and smoke boundary" {
|
||||
|
||||
Reference in New Issue
Block a user