diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Installation.zig | 4 | ||||
| -rw-r--r-- | src/install.zig | 4 | ||||
| -rw-r--r-- | src/list.zig | 13 | ||||
| -rw-r--r-- | src/main.zig | 14 | ||||
| -rw-r--r-- | src/remove.zig | 4 | ||||
| -rw-r--r-- | src/subcommand.zig | 6 | ||||
| -rw-r--r-- | src/switch.zig | 2 | ||||
| -rw-r--r-- | src/update.zig | 2 |
8 files changed, 21 insertions, 28 deletions
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 @@ | |||
| 1 | const curl = @import("curl"); | 1 | const curl = @import("curl"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | const xdg = @import("xdg"); | 3 | const xdg = @import("xdg"); |
| 4 | const zup = @import("zup"); | 4 | const zup = @import("root"); |
| 5 | 5 | ||
| 6 | const Allocator = std.mem.Allocator; | 6 | const Allocator = std.mem.Allocator; |
| 7 | const Config = zup.Config; | 7 | const Config = zup.Config; |
| @@ -109,7 +109,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 109 | continue; | 109 | continue; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.spaces); | 112 | const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.whitespace); |
| 113 | const version = try SemanticVersion.parse(trimmed_ver_str); | 113 | const version = try SemanticVersion.parse(trimmed_ver_str); |
| 114 | const name = try allocator.dupe(u8, item.name); | 114 | const name = try allocator.dupe(u8, item.name); |
| 115 | 115 | ||
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"); | |||
| 2 | const curl = @import("curl"); | 2 | const curl = @import("curl"); |
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const xdg = @import("xdg"); | 4 | const xdg = @import("xdg"); |
| 5 | const zup = @import("zup"); | 5 | const zup = @import("root"); |
| 6 | 6 | ||
| 7 | const Allocator = std.mem.Allocator; | 7 | const Allocator = std.mem.Allocator; |
| 8 | const Config = zup.Config; | 8 | const Config = zup.Config; |
| @@ -24,7 +24,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 24 | var available = try Installation.getAvailableList(config); | 24 | var available = try Installation.getAvailableList(config); |
| 25 | defer Installation.deinitMap(allocator, &available); | 25 | defer Installation.deinitMap(allocator, &available); |
| 26 | 26 | ||
| 27 | return perform(allocator, res.positionals[0], res.args.force, available); | 27 | return perform(allocator, res.positionals[0], res.args.force != 0, available); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: Installations) !void { | 30 | 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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const zup = @import("zup"); | 2 | const zup = @import("root"); |
| 3 | 3 | ||
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| @@ -20,11 +20,11 @@ pub const max_args = 0; | |||
| 20 | pub fn main(comptime Result: type, config: Config, res: Result) !void { | 20 | pub fn main(comptime Result: type, config: Config, res: Result) !void { |
| 21 | const allocator = config.allocator; | 21 | const allocator = config.allocator; |
| 22 | 22 | ||
| 23 | var list_active = res.args.active; | 23 | var list_active = res.args.active != 0; |
| 24 | var list_available = res.args.available; | 24 | var list_available = res.args.available != 0; |
| 25 | var list_installed = res.args.installed; | 25 | var list_installed = res.args.installed != 0; |
| 26 | 26 | ||
| 27 | if (res.args.all) { | 27 | if (res.args.all != 0) { |
| 28 | list_active = true; | 28 | list_active = true; |
| 29 | list_available = true; | 29 | list_available = true; |
| 30 | list_installed = true; | 30 | list_installed = true; |
| @@ -36,8 +36,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 36 | if (list_active) { | 36 | if (list_active) { |
| 37 | const active = try Installation.getActiveName(allocator); | 37 | const active = try Installation.getActiveName(allocator); |
| 38 | defer if (active) |s| allocator.free(s); | 38 | defer if (active) |s| allocator.free(s); |
| 39 | // TODO: zig-bug should I really need to do this? | 39 | try printActive(active); |
| 40 | try printActive(if (active) |a| a else null); | ||
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | if (list_installed) { | 42 | 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( | |||
| 73 | comptime default_fn: anytype, | 73 | comptime default_fn: anytype, |
| 74 | args: anytype, | 74 | args: anytype, |
| 75 | ) !void { | 75 | ) !void { |
| 76 | // TODO: This can still be improved, currently we're looping through all possible values, it could be somehow made | 76 | // TODO: This can still be improved, currently we're looping through all |
| 77 | // into a switch. | 77 | // possible values, it could be somehow made into a switch. |
| 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.{}, default_fn, args); | 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.auto, default_fn, args); |
| 79 | const commands = @typeInfo(Command).Enum.fields; | 79 | const commands = @typeInfo(Command).Enum.fields; |
| 80 | inline for (commands) |command| { | 80 | inline for (commands) |command| { |
| 81 | if (@enumToInt(cmd_enum) == command.value) { | 81 | if (@enumToInt(cmd_enum) == command.value) { |
| 82 | // TODO: zig-bug it cries about modifying a constant if | ||
| 83 | // I just write `return @call(.{}, fun, args);` | ||
| 84 | const fun = @field(@field(@This(), command.name), fn_name); | 82 | const fun = @field(@field(@This(), command.name), fn_name); |
| 85 | return call(fun, args); | 83 | return @call(.auto, fun, args); |
| 86 | } | 84 | } |
| 87 | } | 85 | } |
| 88 | unreachable; | 86 | unreachable; |
| 89 | } | 87 | } |
| 90 | 88 | ||
| 91 | inline fn call(fun: anytype, args: anytype) !void { | ||
| 92 | return @call(.{}, fun, args); | ||
| 93 | } | ||
| 94 | |||
| 95 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { | 89 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { |
| 96 | std.log.err("Unknown subcommand: {s}", .{cmd}); | 90 | std.log.err("Unknown subcommand: {s}", .{cmd}); |
| 97 | return error.ArgError; | 91 | 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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const xdg = @import("xdg"); | 2 | const xdg = @import("xdg"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const Config = zup.Config; | 5 | const Config = zup.Config; |
| 6 | const Installation = zup.Installation; | 6 | const Installation = zup.Installation; |
| @@ -25,7 +25,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 25 | 25 | ||
| 26 | const is_active = try Installation.isActive(allocator, name); | 26 | const is_active = try Installation.isActive(allocator, name); |
| 27 | 27 | ||
| 28 | if (is_active and !res.args.force) { | 28 | if (is_active and res.args.force == 0) { |
| 29 | std.log.err("{s} is the active installation, not removing without --force!", .{name}); | 29 | std.log.err("{s} is the active installation, not removing without --force!", .{name}); |
| 30 | return error.CantRemove; | 30 | return error.CantRemove; |
| 31 | } | 31 | } |
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 @@ | |||
| 1 | const clap = @import("clap"); | 1 | const clap = @import("clap"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const ArgIterator = std.process.ArgIterator; | 5 | const ArgIterator = std.process.ArgIterator; |
| 6 | const Config = zup.Config; | 6 | const Config = zup.Config; |
| @@ -49,11 +49,11 @@ pub fn SubCommand(comptime template: type) type { | |||
| 49 | }; | 49 | }; |
| 50 | defer res.deinit(); | 50 | defer res.deinit(); |
| 51 | 51 | ||
| 52 | if (res.args.help) { | 52 | if (res.args.help != 0) { |
| 53 | return help(name); | 53 | return help(name); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | if (res.args.version) { | 56 | if (res.args.version != 0) { |
| 57 | return zup.printVersion(); | 57 | return zup.printVersion(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const xdg = @import("xdg"); | 2 | const xdg = @import("xdg"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const Config = zup.Config; | 5 | const Config = zup.Config; |
| 6 | const Installation = zup.Installation; | 6 | 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 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const zup = @import("zup"); | 2 | const zup = @import("root"); |
| 3 | 3 | ||
| 4 | const Config = zup.Config; | 4 | const Config = zup.Config; |
| 5 | const Installation = zup.Installation; | 5 | const Installation = zup.Installation; |