From 06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 2 Apr 2023 22:28:09 +0300 Subject: Update to latest zig --- src/Installation.zig | 4 ++-- src/install.zig | 4 ++-- src/list.zig | 13 ++++++------- src/main.zig | 14 ++++---------- src/remove.zig | 4 ++-- src/subcommand.zig | 6 +++--- src/switch.zig | 2 +- src/update.zig | 2 +- 8 files changed, 21 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/Installation.zig b/src/Installation.zig index 4f7a48d..3ff65ea 100644 --- a/src/Installation.zig +++ b/src/Installation.zig @@ -1,7 +1,7 @@ const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); -const zup = @import("zup"); +const zup = @import("root"); const Allocator = std.mem.Allocator; const Config = zup.Config; @@ -109,7 +109,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { continue; } - const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.spaces); + const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.whitespace); const version = try SemanticVersion.parse(trimmed_ver_str); const name = try allocator.dupe(u8, item.name); diff --git a/src/install.zig b/src/install.zig index 27db4bb..2e3efab 100644 --- a/src/install.zig +++ b/src/install.zig @@ -2,7 +2,7 @@ const libarchive = @import("libarchive"); const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); -const zup = @import("zup"); +const zup = @import("root"); const Allocator = std.mem.Allocator; const Config = zup.Config; @@ -24,7 +24,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { var available = try Installation.getAvailableList(config); defer Installation.deinitMap(allocator, &available); - return perform(allocator, res.positionals[0], res.args.force, available); + return perform(allocator, res.positionals[0], res.args.force != 0, available); } pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: Installations) !void { diff --git a/src/list.zig b/src/list.zig index bf95c2c..0a0fee9 100644 --- a/src/list.zig +++ b/src/list.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const zup = @import("zup"); +const zup = @import("root"); const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList; @@ -20,11 +20,11 @@ pub const max_args = 0; pub fn main(comptime Result: type, config: Config, res: Result) !void { const allocator = config.allocator; - var list_active = res.args.active; - var list_available = res.args.available; - var list_installed = res.args.installed; + var list_active = res.args.active != 0; + var list_available = res.args.available != 0; + var list_installed = res.args.installed != 0; - if (res.args.all) { + if (res.args.all != 0) { list_active = true; list_available = true; list_installed = true; @@ -36,8 +36,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { if (list_active) { const active = try Installation.getActiveName(allocator); defer if (active) |s| allocator.free(s); - // TODO: zig-bug should I really need to do this? - try printActive(if (active) |a| a else null); + try printActive(active); } if (list_installed) { diff --git a/src/main.zig b/src/main.zig index 197a224..93356d6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -73,25 +73,19 @@ fn dispatch( comptime default_fn: anytype, args: anytype, ) !void { - // TODO: This can still be improved, currently we're looping through all possible values, it could be somehow made - // into a switch. - const cmd_enum = CommandMap.get(cmd) orelse return @call(.{}, default_fn, args); + // TODO: This can still be improved, currently we're looping through all + // possible values, it could be somehow made into a switch. + const cmd_enum = CommandMap.get(cmd) orelse return @call(.auto, default_fn, args); const commands = @typeInfo(Command).Enum.fields; inline for (commands) |command| { if (@enumToInt(cmd_enum) == command.value) { - // TODO: zig-bug it cries about modifying a constant if - // I just write `return @call(.{}, fun, args);` const fun = @field(@field(@This(), command.name), fn_name); - return call(fun, args); + return @call(.auto, fun, args); } } unreachable; } -inline fn call(fun: anytype, args: anytype) !void { - return @call(.{}, fun, args); -} - fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { std.log.err("Unknown subcommand: {s}", .{cmd}); return error.ArgError; diff --git a/src/remove.zig b/src/remove.zig index f795df7..2d868fb 100644 --- a/src/remove.zig +++ b/src/remove.zig @@ -1,6 +1,6 @@ const std = @import("std"); const xdg = @import("xdg"); -const zup = @import("zup"); +const zup = @import("root"); const Config = zup.Config; const Installation = zup.Installation; @@ -25,7 +25,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { const is_active = try Installation.isActive(allocator, name); - if (is_active and !res.args.force) { + if (is_active and res.args.force == 0) { std.log.err("{s} is the active installation, not removing without --force!", .{name}); return error.CantRemove; } diff --git a/src/subcommand.zig b/src/subcommand.zig index d750e94..09f1b4f 100644 --- a/src/subcommand.zig +++ b/src/subcommand.zig @@ -1,6 +1,6 @@ const clap = @import("clap"); const std = @import("std"); -const zup = @import("zup"); +const zup = @import("root"); const ArgIterator = std.process.ArgIterator; const Config = zup.Config; @@ -49,11 +49,11 @@ pub fn SubCommand(comptime template: type) type { }; defer res.deinit(); - if (res.args.help) { + if (res.args.help != 0) { return help(name); } - if (res.args.version) { + if (res.args.version != 0) { return zup.printVersion(); } diff --git a/src/switch.zig b/src/switch.zig index e5d243f..f90f7d7 100644 --- a/src/switch.zig +++ b/src/switch.zig @@ -1,6 +1,6 @@ const std = @import("std"); const xdg = @import("xdg"); -const zup = @import("zup"); +const zup = @import("root"); const Config = zup.Config; const Installation = zup.Installation; diff --git a/src/update.zig b/src/update.zig index 3451d90..55e6847 100644 --- a/src/update.zig +++ b/src/update.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const zup = @import("zup"); +const zup = @import("root"); const Config = zup.Config; const Installation = zup.Installation; -- cgit v1.2.3