summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig
index f2868b6..197a224 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,3 +1,4 @@
1pub const Config = @import("Config.zig");
1pub const Installation = @import("Installation.zig"); 2pub const Installation = @import("Installation.zig");
2pub const Installations = Installation.Installations; 3pub const Installations = Installation.Installations;
3pub const SubCommand = @import("subcommand.zig").SubCommand; 4pub const SubCommand = @import("subcommand.zig").SubCommand;
@@ -13,20 +14,19 @@ pub const version = SubCommand(Version);
13const std = @import("std"); 14const std = @import("std");
14const zup_config = @import("zup-config"); 15const zup_config = @import("zup-config");
15 16
16const Allocator = std.mem.Allocator;
17const ArgIterator = std.process.ArgIterator; 17const ArgIterator = std.process.ArgIterator;
18const ComptimeStringMap = std.ComptimeStringMap; 18const ComptimeStringMap = std.ComptimeStringMap;
19const GPA = std.heap.GeneralPurposeAllocator(.{}); 19const GPA = std.heap.GeneralPurposeAllocator(.{});
20const Tuple = std.meta.Tuple; 20const Tuple = std.meta.Tuple;
21 21
22// TODO: config for supported triples. while smth like x86_64-macos on aarch64-macos can be hardcoded, that won't be
23// the case for someone with qemu-user on linux
24
25pub fn main() !void { 22pub fn main() !void {
26 var gpa = GPA{}; 23 var gpa = GPA{};
27 const allocator = gpa.allocator(); 24 const allocator = gpa.allocator();
28 defer _ = gpa.deinit(); 25 defer _ = gpa.deinit();
29 26
27 var config = try Config.init(allocator);
28 defer config.deinit();
29
30 var args = try std.process.argsWithAllocator(allocator); 30 var args = try std.process.argsWithAllocator(allocator);
31 defer args.deinit(); 31 defer args.deinit();
32 32
@@ -35,7 +35,7 @@ pub fn main() !void {
35 return Help.mainHelp(); 35 return Help.mainHelp();
36 }; 36 };
37 37
38 return dispatch(cmd, "main", unknownCmd, .{ cmd, allocator, &args }); 38 return dispatch(cmd, "main", unknownCmd, .{ cmd, config, &args });
39} 39}
40 40
41pub fn printVersion() !void { 41pub fn printVersion() !void {
@@ -92,7 +92,7 @@ inline fn call(fun: anytype, args: anytype) !void {
92 return @call(.{}, fun, args); 92 return @call(.{}, fun, args);
93} 93}
94 94
95fn unknownCmd(cmd: []const u8, _: Allocator, _: *ArgIterator) !void { 95fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void {
96 std.log.err("Unknown subcommand: {s}", .{cmd}); 96 std.log.err("Unknown subcommand: {s}", .{cmd});
97 return error.ArgError; 97 return error.ArgError;
98} 98}
@@ -103,7 +103,7 @@ const Help = struct {
103 pub const min_args = 0; 103 pub const min_args = 0;
104 pub const max_args = 1; 104 pub const max_args = 1;
105 105
106 pub fn main(comptime Result: type, _: Allocator, res: Result) !void { 106 pub fn main(comptime Result: type, _: Config, res: Result) !void {
107 if (res.positionals.len == 0) { 107 if (res.positionals.len == 0) {
108 return mainHelp(); 108 return mainHelp();
109 } 109 }
@@ -145,7 +145,7 @@ const Version = struct {
145 pub const min_args = 0; 145 pub const min_args = 0;
146 pub const max_args = 0; 146 pub const max_args = 0;
147 147
148 pub fn main(comptime Result: type, _: Allocator, _: Result) !void { 148 pub fn main(comptime Result: type, _: Config, _: Result) !void {
149 return printVersion(); 149 return printVersion();
150 } 150 }
151}; 151};