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