╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ command.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
230 cli: Command, 231 232 pub fn init(cmd_args: *CommandArgs) !CommandDispatch { 233 const dispatch = try initIgnoreUnused(cmd_args); 234 if (cmd_args.unused_args.count() > 0) { 235 return .{ 236 .invalid = .{ 237 .argument = .{ 238 .command = switch (dispatch) { 239 .invalid => return dispatch, // if there was already an error, return it instead 240 .help => |cmd_kind_maybe| cmd_kind_maybe, 241 .local => null, 242 .cli => |command| command, 243 }, 244 .value = cmd_args.unused_args.keys()[0], 245 }, 246 }, 247 }; 248 } 249 return dispatch; 250 } 251 252 pub fn initIgnoreUnused(cmd_args: *CommandArgs) !CommandDispatch { 253 const show_help = cmd_args.contains("--help"); 254 255 if (cmd_args.command_kind) |command_kind| { 256 if (show_help) { 257 return .{ .help = command_kind }; 258 } else if (try Command.initMaybe(cmd_args)) |cmd| { 259 return .{ .cli = cmd }; 260 } else { 261 return .{ .help = command_kind }; 262 } 263 } else if (cmd_args.command_name) |command_name| { 264 return .{ .invalid = .{ .command = command_name } }; 265 } else if (show_help) { 266 return .{ .help = null }; 267 } else { 268 return .local; 269 } 270 } 271 }; 272