diff options
| author | 2022-04-28 15:27:11 +0300 | |
|---|---|---|
| committer | 2022-04-28 15:29:33 +0300 | |
| commit | 53af0877444ea6c14b1ad5baec94afbeebc5e5e0 (patch) | |
| tree | 837fba9d78c895243f598c95916bff4a4c56f609 /src/main.zig | |
| parent | Add Installation.isActive, use it (diff) | |
| download | zup-53af0877444ea6c14b1ad5baec94afbeebc5e5e0.tar.gz zup-53af0877444ea6c14b1ad5baec94afbeebc5e5e0.tar.xz zup-53af0877444ea6c14b1ad5baec94afbeebc5e5e0.zip | |
Added support for config files
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 16 |
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 @@ | |||
| 1 | pub const Config = @import("Config.zig"); | ||
| 1 | pub const Installation = @import("Installation.zig"); | 2 | pub const Installation = @import("Installation.zig"); |
| 2 | pub const Installations = Installation.Installations; | 3 | pub const Installations = Installation.Installations; |
| 3 | pub const SubCommand = @import("subcommand.zig").SubCommand; | 4 | pub const SubCommand = @import("subcommand.zig").SubCommand; |
| @@ -13,20 +14,19 @@ pub const version = SubCommand(Version); | |||
| 13 | const std = @import("std"); | 14 | const std = @import("std"); |
| 14 | const zup_config = @import("zup-config"); | 15 | const zup_config = @import("zup-config"); |
| 15 | 16 | ||
| 16 | const Allocator = std.mem.Allocator; | ||
| 17 | const ArgIterator = std.process.ArgIterator; | 17 | const ArgIterator = std.process.ArgIterator; |
| 18 | const ComptimeStringMap = std.ComptimeStringMap; | 18 | const ComptimeStringMap = std.ComptimeStringMap; |
| 19 | const GPA = std.heap.GeneralPurposeAllocator(.{}); | 19 | const GPA = std.heap.GeneralPurposeAllocator(.{}); |
| 20 | const Tuple = std.meta.Tuple; | 20 | const 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 | |||
| 25 | pub fn main() !void { | 22 | pub 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 | ||
| 41 | pub fn printVersion() !void { | 41 | pub 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 | ||
| 95 | fn unknownCmd(cmd: []const u8, _: Allocator, _: *ArgIterator) !void { | 95 | fn 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 | }; |