Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ automatically (pinned in `build.zig.zon`).
## Usage

```sh
boo # attach the most recent session, or start one
boo new # new session running $SHELL, attached
boo new work # named session
boo new work -d -- make # create detached, running a command
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .boo,
.version = "0.2.0",
.version = "0.3.0",
.fingerprint = 0x8b7acdfd255f0e34,
.minimum_zig_version = "0.15.2",
.dependencies = .{
Expand Down
5 changes: 2 additions & 3 deletions src/help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ pub const overview =
\\human would see them.
\\
\\usage:
\\ boo [command] [arguments]
\\ boo <command> [arguments]
\\
\\ With no arguments, boo attaches the most recently active
\\ session, or starts a new one if none exist.
\\ With no arguments, boo prints this overview.
\\
\\commands:
\\ new [name] [-d] [-- cmd...] start a session (attach unless -d)
Expand Down
15 changes: 2 additions & 13 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const help = @import("help.zig");
const paths = @import("paths.zig");
const protocol = @import("protocol.zig");

pub const version = "0.2.0";
pub const version = "0.3.0";

/// Exit codes, documented in `boo help`.
const exit_runtime: u8 = 1;
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn main() !void {
defer std.process.argsFree(alloc, argv);
const args: []const [:0]const u8 = @ptrCast(argv[1..]);

if (args.len == 0) return cmdAuto(alloc);
if (args.len == 0) return stdoutWrite(help.overview);

const cmd = args[0];
const rest = args[1..];
Expand Down Expand Up @@ -239,17 +239,6 @@ fn mustControl(

// -- Commands -------------------------------------------------------------

/// Zero-argument boo: attach the most recent session, else create one.
fn cmdAuto(alloc: std.mem.Allocator) !void {
const dir = try paths.socketDir(alloc);
defer alloc.free(dir);
if (try pickMostRecent(alloc, dir)) |name| {
defer alloc.free(name);
return attachLoop(alloc, dir, name);
}
return createSession(alloc, dir, null, false, &.{});
}

fn cmdNew(alloc: std.mem.Allocator, args: []const [:0]const u8) !void {
var name: ?[]const u8 = null;
var detached = false;
Expand Down
35 changes: 10 additions & 25 deletions test/integration.zig
Original file line number Diff line number Diff line change
Expand Up @@ -869,38 +869,23 @@ test "wait --for and --idle observe session output" {
try h.runExit(&.{ "wait", "w1", "--for", "NEVER-APPEARS", "--timeout", "300ms" }, 4);
}

test "zero-arg boo creates a session, then reattaches it" {
test "zero-arg boo prints the help overview" {
const alloc = std.testing.allocator;
var h = try Harness.init(alloc);
defer h.deinit();

// No sessions: boo starts one running the default shell. Wait
// for the attach repaint before typing; input sent before the
// client enters raw mode is flushed by tcsetattr.
var first = try PtyClient.spawn(&h, &.{}, 24, 80);
defer first.deinit();
try first.waitFor("\x1b[H\x1b[2J");
try first.send("echo Z-MARK-$((70+7))\r");
try first.waitFor("Z-MARK-77");
try first.send("\x01d");
try first.waitFor("detached from");
try std.testing.expectEqual(@as(u32, 0), try first.waitExit());
const result = try h.run(&.{});
defer alloc.free(result.stdout);
defer alloc.free(result.stderr);
try std.testing.expect(result.term == .Exited and result.term.Exited == 0);
try std.testing.expect(std.mem.indexOf(u8, result.stdout, "usage:") != null);
try std.testing.expect(std.mem.indexOf(u8, result.stdout, "commands:") != null);

const ls = try h.run(&.{ "ls", "--json" });
// Unlike earlier versions, no session is created or attached.
const ls = try h.run(&.{"ls"});
defer alloc.free(ls.stdout);
defer alloc.free(ls.stderr);
var parsed = try std.json.parseFromSlice(std.json.Value, alloc, ls.stdout, .{});
defer parsed.deinit();
try std.testing.expectEqual(@as(usize, 1), parsed.value.array.items.len);

// One live session: zero-arg boo attaches it instead of creating
// another; the repaint proves it is the same session.
var second = try PtyClient.spawn(&h, &.{}, 24, 80);
defer second.deinit();
try second.waitFor("Z-MARK-77");
try second.send("\x01d");
try second.waitFor("detached from");
try std.testing.expectEqual(@as(u32, 0), try second.waitExit());
try std.testing.expect(std.mem.indexOf(u8, ls.stdout, "No sessions") != null);
}

test "exorcise banishes every session" {
Expand Down
Loading