╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ command.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
211 invalid: union(enum) { 212 command: []const u8, 213 argument: struct { 214 command: ?CommandKind, 215 value: []const u8, 216 }, 217 }, 218 help: ?CommandKind, 219 local, 220 cli: Command, 221 222 pub fn init(cmd_args: *CommandArgs) !CommandDispatch { 223 const dispatch = try initIgnoreUnused(cmd_args); 224 if (cmd_args.unused_args.count() > 0) { 225 return .{ 226 .invalid = .{ 227 .argument = .{ 228 .command = switch (dispatch) { 229 .invalid => return dispatch, // if there was already an error, return it instead 230 .help => |cmd_kind_maybe| cmd_kind_maybe, 231 .local => null, 232 .cli => |command| command, 233 }, 234 .value = cmd_args.unused_args.keys()[0], 235 }, 236 }, 237 }; 238 } 239 return dispatch; 240 } 241 242 pub fn initIgnoreUnused(cmd_args: *CommandArgs) !CommandDispatch { 243 const show_help = cmd_args.contains("--help"); 244 245 if (cmd_args.command_kind) |command_kind| { 246 if (show_help) { 247 return .{ .help = command_kind }; 248 } else if (try Command.initMaybe(cmd_args)) |cmd| { 249 return .{ .cli = cmd }; 250 } else { 251 return .{ .help = command_kind }; 252 } 253 } else if (cmd_args.command_name) |command_name| { 254 return .{ .invalid = .{ .command = command_name } }; 255 } else if (show_help) { 256 return .{ .help = null }; 257 } else { 258 return .local; 259 } 260 } 261 }; 262