╭ changed ──────╮ │src/command.zig│ ╰───────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────╮ │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 }, │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────╯