╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ command.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
211 } 212 if (cmd_args.get("--wui-listen")) |value_maybe| options.wui_listen = value_maybe orelse return error.WuiListenNeedsValue; 213 if (cmd_args.get("--data-dir")) |value_maybe| options.data_dir = value_maybe orelse return error.DataDirNeedsValue; 214 return options; 215 } 216 217 /// parses the given args into a command if valid, and determines how it should be run 218 /// (via the TUI or CLI). 219 pub const CommandDispatch = union(enum) { 220 invalid: union(enum) { 221 command: []const u8, 222 argument: struct { 223 command: ?CommandKind, 224 value: []const u8, 225 }, 226 }, 227 help: ?CommandKind, 228 local, 229 cli: Command, 230 231 pub fn init(cmd_args: *CommandArgs) !CommandDispatch { 232 const dispatch = try initIgnoreUnused(cmd_args); 233 if (cmd_args.unused_args.count() > 0) { 234 return .{ 235 .invalid = .{ 236 .argument = .{ 237 .command = switch (dispatch) { 238 .invalid => return dispatch, // if there was already an error, return it instead 239 .help => |cmd_kind_maybe| cmd_kind_maybe, 240 .local => null, 241 .cli => |command| command, 242 }, 243 .value = cmd_args.unused_args.keys()[0], 244 }, 245 }, 246 }; 247 } 248 return dispatch; 249 } 250 251 pub fn initIgnoreUnused(cmd_args: *CommandArgs) !CommandDispatch { 252 const show_help = cmd_args.contains("--help"); 253 254 if (cmd_args.command_kind) |command_kind| { 255 if (show_help) { 256 return .{ .help = command_kind }; 257 } else if (try Command.initMaybe(cmd_args)) |cmd| { 258 return .{ .cli = cmd }; 259 } else { 260 return .{ .help = command_kind }; 261 } 262 } else if (cmd_args.command_name) |command_name| { 263 return .{ .invalid = .{ .command = command_name } }; 264 } else if (show_help) { 265 return .{ .help = null }; 266 } else { 267 return .local; 268 } 269 } 270 }; 271