summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-07-22 06:29:25 +0300
committerGravatar Uko Kokņevičs2025-07-22 06:29:25 +0300
commit73fd32eb28753584edb160fc11b0c16078a2ed6d (patch)
tree6ced78d1293bea471d6fb3dd29a57e860960385e /src
parentDocument that zup 0.6.0 compiles with zig 0.14.1 as well (diff)
downloadzup-main.tar.gz
zup-main.tar.xz
zup-main.zip
Update ZigHEADmain
Diffstat (limited to 'src')
-rw-r--r--src/Config.zig7
-rw-r--r--src/install.zig2
-rw-r--r--src/list.zig33
-rw-r--r--src/main.zig16
-rw-r--r--src/subcommand.zig10
-rw-r--r--src/update.zig2
6 files changed, 43 insertions, 27 deletions
diff --git a/src/Config.zig b/src/Config.zig
index ba8f496..1e4a9bd 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -63,7 +63,10 @@ fn readConfig(self: *Config, file: File) !void {
63 supported_targets: [][]u8, 63 supported_targets: [][]u8,
64 }; 64 };
65 65
66 var reader = std.json.reader(allocator, file.reader()); 66 const fileBuf = try allocator.alloc(u8, 4096);
67 var fileReader = file.reader(fileBuf);
68
69 var reader = std.json.Reader.init(allocator, &fileReader.interface);
67 defer reader.deinit(); 70 defer reader.deinit();
68 71
69 const parsed = try std.json.parseFromTokenSourceLeaky( 72 const parsed = try std.json.parseFromTokenSourceLeaky(
@@ -90,7 +93,7 @@ fn readConfig(self: *Config, file: File) !void {
90 }; 93 };
91 94
92 const resolved = std.zig.system.resolveTargetQuery(query) catch |e| { 95 const resolved = std.zig.system.resolveTargetQuery(query) catch |e| {
93 std.log.warn("Failed to resolve '{s}' as a target: {}", .{ target, e}); 96 std.log.warn("Failed to resolve '{s}' as a target: {}", .{ target, e });
94 continue; 97 continue;
95 }; 98 };
96 99
diff --git a/src/install.zig b/src/install.zig
index 8a16e49..2b6d44f 100644
--- a/src/install.zig
+++ b/src/install.zig
@@ -51,7 +51,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I
51 }; 51 };
52 defer allocator.free(installation_dir); 52 defer allocator.free(installation_dir);
53 53
54 std.log.info("Installing {s}, version {}", .{ name, installation.version }); 54 std.log.info("Installing {s}, version {f}", .{ name, installation.version });
55 55
56 std.log.info("Downloading from {s}...", .{installation.url_str.?}); 56 std.log.info("Downloading from {s}...", .{installation.url_str.?});
57 57
diff --git a/src/list.zig b/src/list.zig
index 9ff26c2..72f3d91 100644
--- a/src/list.zig
+++ b/src/list.zig
@@ -4,8 +4,10 @@ const zup = @import("root");
4const Allocator = std.mem.Allocator; 4const Allocator = std.mem.Allocator;
5const ArrayList = std.ArrayList; 5const ArrayList = std.ArrayList;
6const Config = zup.Config; 6const Config = zup.Config;
7const File = std.fs.File;
7const Installation = zup.Installation; 8const Installation = zup.Installation;
8const Installations = zup.Installations; 9const Installations = zup.Installations;
10const Writer = std.io.Writer;
9 11
10pub const params = 12pub const params =
11 \\--active List the active version 13 \\--active List the active version
@@ -33,27 +35,33 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void {
33 list_installed = true; 35 list_installed = true;
34 } 36 }
35 37
38 const buf = try allocator.alloc(u8, 4096);
39 defer allocator.free(buf);
40
41 var stdout = File.stdout().writer(buf);
42
36 if (list_active) { 43 if (list_active) {
37 const active = try Installation.getActiveName(allocator); 44 const active = try Installation.getActiveName(allocator);
38 defer if (active) |s| allocator.free(s); 45 defer if (active) |s| allocator.free(s);
39 try printActive(active); 46 try printActive(&stdout.interface, active);
40 } 47 }
41 48
42 if (list_installed) { 49 if (list_installed) {
43 var installed = try Installation.getInstalledList(allocator); 50 var installed = try Installation.getInstalledList(allocator);
44 defer Installation.deinitMap(allocator, &installed); 51 defer Installation.deinitMap(allocator, &installed);
45 try printInstalledList(allocator, installed); 52 try printInstalledList(allocator, &stdout.interface, installed);
46 } 53 }
47 54
48 if (list_available) { 55 if (list_available) {
49 var available = try Installation.getAvailableList(config); 56 var available = try Installation.getAvailableList(config);
50 defer Installation.deinitMap(allocator, &available); 57 defer Installation.deinitMap(allocator, &available);
51 try printAvailableList(allocator, available); 58 try printAvailableList(allocator, &stdout.interface, available);
52 } 59 }
60
61 try stdout.interface.flush();
53} 62}
54 63
55fn printActive(active: ?[]const u8) !void { 64fn printActive(writer: *Writer, active: ?[]const u8) !void {
56 const writer = std.io.getStdOut().writer();
57 try writer.writeAll("Active installation: "); 65 try writer.writeAll("Active installation: ");
58 if (active) |act| { 66 if (active) |act| {
59 try writer.writeAll(act); 67 try writer.writeAll(act);
@@ -64,19 +72,17 @@ fn printActive(active: ?[]const u8) !void {
64 try writer.writeByte('\n'); 72 try writer.writeByte('\n');
65} 73}
66 74
67fn printAvailableList(allocator: Allocator, avail: Installations) !void { 75fn printAvailableList(allocator: Allocator, writer: *Writer, avail: Installations) !void {
68 const writer = std.io.getStdOut().writer();
69 try writer.writeAll("Available versions:\n"); 76 try writer.writeAll("Available versions:\n");
70 try printList(allocator, avail); 77 try printList(allocator, writer, avail);
71} 78}
72 79
73fn printInstalledList(allocator: Allocator, installed: Installations) !void { 80fn printInstalledList(allocator: Allocator, writer: *Writer, installed: Installations) !void {
74 const writer = std.io.getStdOut().writer();
75 try writer.writeAll("Installed versions:\n"); 81 try writer.writeAll("Installed versions:\n");
76 try printList(allocator, installed); 82 try printList(allocator, writer, installed);
77} 83}
78 84
79fn printList(allocator: Allocator, installations: Installations) !void { 85fn printList(allocator: Allocator, writer: *Writer, installations: Installations) !void {
80 const InstallationAndName = struct { 86 const InstallationAndName = struct {
81 name: []const u8, 87 name: []const u8,
82 installation: Installation, 88 installation: Installation,
@@ -98,8 +104,7 @@ fn printList(allocator: Allocator, installations: Installations) !void {
98 104
99 std.mem.sort(InstallationAndName, list.items, {}, InstallationAndName.lessThan); 105 std.mem.sort(InstallationAndName, list.items, {}, InstallationAndName.lessThan);
100 106
101 const writer = std.io.getStdOut().writer();
102 for (list.items) |item| { 107 for (list.items) |item| {
103 try writer.print(" {s}: {}\n", .{ item.name, item.installation.version }); 108 try writer.print(" {s}: {f}\n", .{ item.name, item.installation.version });
104 } 109 }
105} 110}
diff --git a/src/main.zig b/src/main.zig
index c7e3844..b4f06a7 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -16,6 +16,7 @@ const std = @import("std");
16const zup_config = @import("zup-config"); 16const zup_config = @import("zup-config");
17 17
18const ArgIterator = std.process.ArgIterator; 18const ArgIterator = std.process.ArgIterator;
19const File = std.fs.File;
19const GPA = std.heap.GeneralPurposeAllocator(.{}); 20const GPA = std.heap.GeneralPurposeAllocator(.{});
20const StaticStringMap = std.StaticStringMap; 21const StaticStringMap = std.StaticStringMap;
21const Tuple = std.meta.Tuple; 22const Tuple = std.meta.Tuple;
@@ -40,7 +41,10 @@ pub fn main() !void {
40} 41}
41 42
42pub fn printVersion() !void { 43pub fn printVersion() !void {
43 return std.io.getStdErr().writer().print("{}\n", .{zup_config.version}); 44 var buf: [1024]u8 = undefined;
45 var stderr = File.stderr().writer(&buf);
46 try stderr.interface.print("{f}\n", .{zup_config.version});
47 return stderr.interface.flush();
44} 48}
45 49
46const Command = enum { 50const Command = enum {
@@ -106,8 +110,9 @@ const Help = struct {
106 } 110 }
107 111
108 pub fn mainHelp() !void { 112 pub fn mainHelp() !void {
109 const writer = std.io.getStdErr().writer(); 113 var buf: [1024]u8 = undefined;
110 try writer.writeAll( 114 var stderr = File.stderr().writer(&buf);
115 try stderr.interface.writeAll(
111 \\USAGE: zup <COMMAND> 116 \\USAGE: zup <COMMAND>
112 \\ 117 \\
113 \\These are the common Zup commands: 118 \\These are the common Zup commands:
@@ -123,6 +128,7 @@ const Help = struct {
123 \\You can find out more about a command by running `zup help <command>`. 128 \\You can find out more about a command by running `zup help <command>`.
124 \\ 129 \\
125 ); 130 );
131 return stderr.interface.flush();
126 } 132 }
127 133
128 fn unknownHelp(cmd: []const u8) !void { 134 fn unknownHelp(cmd: []const u8) !void {
@@ -142,7 +148,3 @@ const Version = struct {
142 return printVersion(); 148 return printVersion();
143 } 149 }
144}; 150};
145
146test "basic test" {
147 try std.testing.expectEqual(10, 3 + 7);
148}
diff --git a/src/subcommand.zig b/src/subcommand.zig
index 8fde170..6a6259e 100644
--- a/src/subcommand.zig
+++ b/src/subcommand.zig
@@ -21,7 +21,9 @@ pub fn SubCommand(comptime template: type) type {
21 ++ template.params); 21 ++ template.params);
22 22
23 pub fn help(name: []const u8) !void { 23 pub fn help(name: []const u8) !void {
24 const writer = std.io.getStdErr().writer(); 24 var buf: [1024]u8 = undefined;
25 var stderr = std.fs.File.stderr().writer(&buf);
26 const writer = &stderr.interface;
25 try writer.print("USAGE: zup {s} ", .{name}); 27 try writer.print("USAGE: zup {s} ", .{name});
26 try clap.usage(writer, clap.Help, &params); 28 try clap.usage(writer, clap.Help, &params);
27 try writer.writeAll("\n\n"); 29 try writer.writeAll("\n\n");
@@ -33,6 +35,7 @@ pub fn SubCommand(comptime template: type) type {
33 .spacing_between_parameters = 0, 35 .spacing_between_parameters = 0,
34 }); 36 });
35 try writer.writeAll("\n" ++ template.description ++ "\n"); 37 try writer.writeAll("\n" ++ template.description ++ "\n");
38 return writer.flush();
36 } 39 }
37 40
38 pub fn main(name: []const u8, config: Config, args: *ArgIterator) !void { 41 pub fn main(name: []const u8, config: Config, args: *ArgIterator) !void {
@@ -43,7 +46,10 @@ pub fn SubCommand(comptime template: type) type {
43 .allocator = allocator, 46 .allocator = allocator,
44 .diagnostic = &diag, 47 .diagnostic = &diag,
45 }) catch |err| { 48 }) catch |err| {
46 diag.report(std.io.getStdErr().writer(), err) catch {}; 49 var buf: [1024]u8 = undefined;
50 var stderr = std.fs.File.stderr().writer(&buf);
51 diag.report(&stderr.interface, err) catch {};
52 stderr.interface.flush() catch {};
47 try help(name); 53 try help(name);
48 return err; 54 return err;
49 }; 55 };
diff --git a/src/update.zig b/src/update.zig
index fc1ab51..6ee7951 100644
--- a/src/update.zig
+++ b/src/update.zig
@@ -26,7 +26,7 @@ pub fn main(comptime Result: type, config: Config, _: Result) !void {
26 const inst = kv.value_ptr.*; 26 const inst = kv.value_ptr.*;
27 if (available.get(name)) |avail| { 27 if (available.get(name)) |avail| {
28 if (avail.version.order(inst.version) == .gt) { 28 if (avail.version.order(inst.version) == .gt) {
29 std.log.info("Updating {s} from {} to {}...", .{ name, inst.version, avail.version }); 29 std.log.info("Updating {s} from {f} to {f}...", .{ name, inst.version, avail.version });
30 try zup.install.base.perform(allocator, name, true, available); 30 try zup.install.base.perform(allocator, name, true, available);
31 } 31 }
32 } 32 }