╭ changed ──────╮ │src/command.zig│ ╰───────────────╯ ╭──────────────────────────────────────╮ │1 const std = @import("std"); │ │2 -const xit = @import("xit"); │ │3 -const rp = xit.repo; │ │4 -const hash = xit.hash; │ │2 +const srv = @import("./serve.zig");│ │3 │ │4 pub const CommandKind = enum { │ │5 serve, │ ╰──────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │188 /// parses the args into a format that can be directly used by a repo. │ │189 /// if any additional allocation needs to be done, the arena inside the cmd args will be used.│ │190 pub const Command = union(CommandKind) { │ │193 - serve: struct { │ │194 - http_listen: []const u8, │ │195 - ssh_listen: []const u8, │ │196 - wui_listen: []const u8, │ │197 - data_dir: []const u8, │ │198 - tui: bool, │ │199 - }, │ │191 + serve: srv.Options, │ │192 ssh_helper: struct { │ │193 ssh_connect: []const u8, │ │194 service: ?[]const u8, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │201 .serve => { │ │202 if (cmd_args.positional_args.len != 0) return null; │ │203 │ │212 - return .{ .serve = .{ │ │213 - .http_listen = (cmd_args.get("--http-listen") orelse null) orelse "127.0.0.1:8080",│ │214 - .ssh_listen = (cmd_args.get("--ssh-listen") orelse null) orelse "127.0.0.1:8081", │ │215 - .wui_listen = (cmd_args.get("--wui-listen") orelse null) orelse "127.0.0.1:8082", │ │216 - .data_dir = (cmd_args.get("--data-dir") orelse null) orelse ".", │ │217 - .tui = cmd_args.contains("--tui"), │ │218 - } }; │ │204 + var options: srv.Options = .{}; │ │205 + if (cmd_args.get("--http-listen")) |val_maybe| { │ │206 + options.http_listen = val_maybe orelse return error.HttpListenNeedsValue; │ │207 + } │ │208 + if (cmd_args.get("--ssh-listen")) |val_maybe| { │ │209 + options.ssh_listen = val_maybe orelse return error.SshListenNeedsValue; │ │210 + } │ │211 + if (cmd_args.get("--wui-listen")) |val_maybe| { │ │212 + options.wui_listen = val_maybe orelse return error.WuiListenNeedsValue; │ │213 + } │ │214 + if (cmd_args.get("--data-dir")) |val_maybe| { │ │215 + options.data_dir = val_maybe orelse return error.DataDirNeedsValue; │ │216 + } │ │217 + if (cmd_args.contains("--tui")) options.tui = true; │ │218 + │ │219 + return .{ .serve = options }; │ │220 }, │ │221 .ssh_helper => { │ │222 if (cmd_args.positional_args.len > 1) return null; │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │223 │ │224 + const options: srv.Options = .{}; │ │225 + │ │226 return .{ .ssh_helper = .{ │ │224 - .ssh_connect = (cmd_args.get("--ssh-connect") orelse null) orelse "127.0.0.1:8081", │ │225 - .service = (cmd_args.get("--service") orelse null), │ │227 + .ssh_connect = if (cmd_args.get("--ssh-connect")) |val_maybe| │ │228 + val_maybe orelse options.ssh_listen │ │229 + else │ │230 + return error.SshListenNeedsValue, │ │231 + .service = if (cmd_args.get("--service")) |val_maybe| │ │232 + val_maybe orelse return error.ServiceNeedsValue │ │233 + else │ │234 + null, │ │235 .dir = if (cmd_args.positional_args.len == 1) cmd_args.positional_args[0] else null,│ │236 } }; │ │237 }, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ───╮ │src/main.zig│ ╰────────────╯ ╭──────────────────────────────────────────────────╮ │3 const xit = @import("xit"); │ │4 const rp = xit.repo; │ │5 const cmd = @import("./command.zig"); │ │6 -const serve = @import("./serve.zig"); │ │6 +const srv = @import("./serve.zig"); │ │7 const ssh_helper = @import("./ssh_helper.zig");│ │8 │ │9 pub const RunOpts = struct { │ ╰──────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────╮ │76 .help => |cmd_kind_maybe| try cmd.printHelp(cmd_kind_maybe, run_opts.out), │ │77 .cli => |cli_cmd| switch (cli_cmd) { │ │78 .serve => { │ │79 - try serve.run(repo_kind, any_repo_opts, io, allocator, cwd_path, .{│ │79 + try srv.run(repo_kind, any_repo_opts, io, allocator, cwd_path, .{ │ │80 .http_listen = cli_cmd.serve.http_listen, │ │81 .ssh_listen = cli_cmd.serve.ssh_listen, │ │82 .wui_listen = cli_cmd.serve.wui_listen, │ ╰───────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ────╮ │src/serve.zig│ ╰─────────────╯ ╭───────────────────────────────────────────────────╮ │ 6 const web = @import("./web.zig"); │ │ 7 │ │ 8 pub const Options = struct { │ │ 9 - http_listen: []const u8, │ │10 - ssh_listen: []const u8, │ │11 - wui_listen: []const u8, │ │12 - data_dir: []const u8, │ │13 - tui: bool, │ │ 9 + http_listen: []const u8 = "127.0.0.1:8080",│ │10 + ssh_listen: []const u8 = "127.0.0.1:8081", │ │11 + wui_listen: []const u8 = "127.0.0.1:8082", │ │12 + data_dir: []const u8 = ".", │ │13 + tui: bool = false, │ │14 }; │ │15 │ │16 const ListenAddress = struct { │ ╰───────────────────────────────────────────────────╯