| ... | @@ -58,8 +58,7 @@ pub fn main() !void { | ... | @@ -58,8 +58,7 @@ pub fn main() !void { |
| 58 | stderr = &stderr_file.outStream().stream; | 58 | stderr = &stderr_file.outStream().stream; |
| 59 | | 59 | |
| 60 | const args = try process.argsAlloc(allocator); | 60 | const args = try process.argsAlloc(allocator); |
| 61 | // TODO I'm getting unreachable code here, which shouldn't happen | 61 | defer process.argsFree(allocator, args); |
| 62 | //defer process.argsFree(allocator, args); | | |
| 63 | | 62 | |
| 64 | if (args.len <= 1) { | 63 | if (args.len <= 1) { |
| 65 | try stderr.write("expected command argument\n\n"); | 64 | try stderr.write("expected command argument\n\n"); |
| ... | @@ -67,64 +66,33 @@ pub fn main() !void { | ... | @@ -67,64 +66,33 @@ pub fn main() !void { |
| 67 | process.exit(1); | 66 | process.exit(1); |
| 68 | } | 67 | } |
| 69 | | 68 | |
| 70 | const commands = [_]Command{ | 69 | const cmd = args[1]; |
| 71 | Command{ | 70 | const cmd_args = args[2..]; |
| 72 | .name = "build-exe", | 71 | if (mem.eql(u8, cmd, "build-exe")) { |
| 73 | .exec = cmdBuildExe, | 72 | return buildOutputType(allocator, cmd_args, .Exe); |
| 74 | }, | 73 | } else if (mem.eql(u8, cmd, "build-lib")) { |
| 75 | Command{ | 74 | return buildOutputType(allocator, cmd_args, .Lib); |
| 76 | .name = "build-lib", | 75 | } else if (mem.eql(u8, cmd, "build-obj")) { |
| 77 | .exec = cmdBuildLib, | 76 | return buildOutputType(allocator, cmd_args, .Obj); |
| 78 | }, | 77 | } else if (mem.eql(u8, cmd, "fmt")) { |
| 79 | Command{ | 78 | return cmdFmt(allocator, cmd_args); |
| 80 | .name = "build-obj", | 79 | } else if (mem.eql(u8, cmd, "libc")) { |
| 81 | .exec = cmdBuildObj, | 80 | return cmdLibC(allocator, cmd_args); |
| 82 | }, | 81 | } else if (mem.eql(u8, cmd, "targets")) { |
| 83 | Command{ | 82 | return cmdTargets(allocator, cmd_args); |
| 84 | .name = "fmt", | 83 | } else if (mem.eql(u8, cmd, "version")) { |
| 85 | .exec = cmdFmt, | 84 | return cmdVersion(allocator, cmd_args); |
| 86 | }, | 85 | } else if (mem.eql(u8, cmd, "zen")) { |
| 87 | Command{ | 86 | return cmdZen(allocator, cmd_args); |
| 88 | .name = "libc", | 87 | } else if (mem.eql(u8, cmd, "help")) { |
| 89 | .exec = cmdLibC, | 88 | return cmdHelp(allocator, cmd_args); |
| 90 | }, | 89 | } else if (mem.eql(u8, cmd, "internal")) { |
| 91 | Command{ | 90 | return cmdInternal(allocator, cmd_args); |
| 92 | .name = "targets", | 91 | } else { |
| 93 | .exec = cmdTargets, | 92 | try stderr.print("unknown command: {}\n\n", .{args[1]}); |
| 94 | }, | 93 | try stderr.write(usage); |
| 95 | Command{ | 94 | process.exit(1); |
| 96 | .name = "version", | | |
| 97 | .exec = cmdVersion, | | |
| 98 | }, | | |
| 99 | Command{ | | |
| 100 | .name = "zen", | | |
| 101 | .exec = cmdZen, | | |
| 102 | }, | | |
| 103 | | | |
| 104 | // undocumented commands | | |
| 105 | Command{ | | |
| 106 | .name = "help", | | |
| 107 | .exec = cmdHelp, | | |
| 108 | }, | | |
| 109 | Command{ | | |
| 110 | .name = "internal", | | |
| 111 | .exec = cmdInternal, | | |
| 112 | }, | | |
| 113 | }; | | |
| 114 | | | |
| 115 | inline for (commands) |command| { | | |
| 116 | if (mem.eql(u8, command.name, args[1])) { | | |
| 117 | var frame = try allocator.create(@Frame(command.exec)); | | |
| 118 | defer allocator.destroy(frame); | | |
| 119 | frame.* = async command.exec(allocator, args[2..]); | | |
| 120 | return await frame; | | |
| 121 | } | | |
| 122 | } | 95 | } |
| 123 | | | |
| 124 | try stderr.print("unknown command: {}\n\n", .{args[1]}); | | |
| 125 | try stderr.write(usage); | | |
| 126 | process.argsFree(allocator, args); | | |
| 127 | process.exit(1); | | |
| 128 | } | 96 | } |
| 129 | | 97 | |
| 130 | const usage_build_generic = | 98 | const usage_build_generic = |
| ... | @@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { | ... | @@ -555,18 +523,6 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { |
| 555 | } | 523 | } |
| 556 | } | 524 | } |
| 557 | | 525 | |
| 558 | fn cmdBuildExe(allocator: *Allocator, args: []const []const u8) !void { | | |
| 559 | return buildOutputType(allocator, args, Compilation.Kind.Exe); | | |
| 560 | } | | |
| 561 | | | |
| 562 | fn cmdBuildLib(allocator: *Allocator, args: []const []const u8) !void { | | |
| 563 | return buildOutputType(allocator, args, Compilation.Kind.Lib); | | |
| 564 | } | | |
| 565 | | | |
| 566 | fn cmdBuildObj(allocator: *Allocator, args: []const []const u8) !void { | | |
| 567 | return buildOutputType(allocator, args, Compilation.Kind.Obj); | | |
| 568 | } | | |
| 569 | | | |
| 570 | pub const usage_fmt = | 526 | pub const usage_fmt = |
| 571 | \\usage: zig fmt [file]... | 527 | \\usage: zig fmt [file]... |
| 572 | \\ | 528 | \\ |