summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2023-04-02 22:28:09 +0300
committerGravatar Uko Kokņevičs2023-04-02 22:30:53 +0300
commit06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5 (patch)
tree1d8261677108400367497a1adec01135e18ad6f5 /src
parentActually use my zig-curl instead of zelda. (diff)
downloadzup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.tar.gz
zup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.tar.xz
zup-06a9ac758c3c201625cbc17d3ccc0f8eea19cdf5.zip
Update to latest zig
Diffstat (limited to 'src')
-rw-r--r--src/Installation.zig4
-rw-r--r--src/install.zig4
-rw-r--r--src/list.zig13
-rw-r--r--src/main.zig14
-rw-r--r--src/remove.zig4
-rw-r--r--src/subcommand.zig6
-rw-r--r--src/switch.zig2
-rw-r--r--src/update.zig2
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 @@
1const curl = @import("curl"); 1const curl = @import("curl");
2const std = @import("std"); 2const std = @import("std");
3const xdg = @import("xdg"); 3const xdg = @import("xdg");
4const zup = @import("zup"); 4const zup = @import("root");
5 5
6const Allocator = std.mem.Allocator; 6const Allocator = std.mem.Allocator;
7const Config = zup.Config; 7const 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");
2const curl = @import("curl"); 2const curl = @import("curl");
3const std = @import("std"); 3const std = @import("std");
4const xdg = @import("xdg"); 4const xdg = @import("xdg");
5const zup = @import("zup"); 5const zup = @import("root");
6 6
7const Allocator = std.mem.Allocator; 7const Allocator = std.mem.Allocator;
8const Config = zup.Config; 8const 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
30pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: Installations) !void { 30pub 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 @@
1const std = @import("std"); 1const std = @import("std");
2const zup = @import("zup"); 2const zup = @import("root");
3 3
4const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
5const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
@@ -20,11 +20,11 @@ pub const max_args = 0;
20pub fn main(comptime Result: type, config: Config, res: Result) !void { 20pub 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
91inline fn call(fun: anytype, args: anytype) !void {
92 return @call(.{}, fun, args);
93}
94
95fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { 89fn 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 @@
1const std = @import("std"); 1const std = @import("std");
2const xdg = @import("xdg"); 2const xdg = @import("xdg");
3const zup = @import("zup"); 3const zup = @import("root");
4 4
5const Config = zup.Config; 5const Config = zup.Config;
6const Installation = zup.Installation; 6const 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 @@
1const clap = @import("clap"); 1const clap = @import("clap");
2const std = @import("std"); 2const std = @import("std");
3const zup = @import("zup"); 3const zup = @import("root");
4 4
5const ArgIterator = std.process.ArgIterator; 5const ArgIterator = std.process.ArgIterator;
6const Config = zup.Config; 6const 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 @@
1const std = @import("std"); 1const std = @import("std");
2const xdg = @import("xdg"); 2const xdg = @import("xdg");
3const zup = @import("zup"); 3const zup = @import("root");
4 4
5const Config = zup.Config; 5const Config = zup.Config;
6const Installation = zup.Installation; 6const 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 @@
1const std = @import("std"); 1const std = @import("std");
2const zup = @import("zup"); 2const zup = @import("root");
3 3
4const Config = zup.Config; 4const Config = zup.Config;
5const Installation = zup.Installation; 5const Installation = zup.Installation;