Skip to content

Commit 6758528

Browse files
chrisbbreuerclaude
andcommitted
revert: restore Zig 0.16-dev APIs (will upload dev Zig to pantry)
Reverts the 0.15.1 API downgrade. The repos should target 0.16-dev. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 39d61c2 commit 6758528

7 files changed

Lines changed: 189 additions & 226 deletions

File tree

src/bump.zig

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ pub const BumpResult = struct {
2929
}
3030
};
3131

32-
fn termSuccess(term: std.process.Child.Term) bool {
33-
return switch (term) {
34-
.Exited => |code| code == 0,
35-
else => false,
36-
};
37-
}
38-
3932
pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
4033
const config = options.config;
4134

@@ -46,12 +39,10 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
4639
std.debug.print("Warning: You have uncommitted changes.\n", .{});
4740
if (!config.yes) {
4841
std.debug.print("Continue anyway? (y/N): ", .{});
49-
const stdin = std.fs.File.stdin();
42+
const stdin = std.io.getStdIn().reader();
5043
var buf: [10]u8 = undefined;
51-
const n = stdin.read(&buf) catch return error.Cancelled;
52-
if (n == 0) return error.Cancelled;
53-
const input = std.mem.trim(u8, buf[0..n], &std.ascii.whitespace);
54-
if (input.len == 0 or (input[0] != 'y' and input[0] != 'Y')) {
44+
const input = try stdin.readUntilDelimiterOrEof(&buf, '\n');
45+
if (input == null or (input.?.len > 0 and input.?[0] != 'y' and input.?[0] != 'Y')) {
5546
return error.Cancelled;
5647
}
5748
}
@@ -127,11 +118,10 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
127118
// Confirmation prompt
128119
if (!config.yes and !config.ci) {
129120
std.debug.print("\nWill update {d} file(s). Continue? (Y/n): ", .{files_to_update.len});
130-
const stdin = std.fs.File.stdin();
121+
const stdin = std.io.getStdIn().reader();
131122
var buf: [10]u8 = undefined;
132-
const n = stdin.read(&buf) catch return error.Cancelled;
133-
if (n > 0) {
134-
const inp = std.mem.trim(u8, buf[0..n], &std.ascii.whitespace);
123+
const input = try stdin.readUntilDelimiterOrEof(&buf, '\n');
124+
if (input) |inp| {
135125
if (inp.len > 0 and inp[0] != 'y' and inp[0] != 'Y' and inp[0] != '\r') {
136126
return error.Cancelled;
137127
}
@@ -166,12 +156,12 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
166156
}
167157

168158
// Update all files
169-
var updated_files: std.ArrayList([]const u8) = .empty;
159+
var updated_files = std.ArrayList([]const u8).init(allocator);
170160
errdefer {
171161
for (updated_files.items) |file| {
172162
allocator.free(file);
173163
}
174-
updated_files.deinit(allocator);
164+
updated_files.deinit();
175165
}
176166

177167
for (files_to_update) |file_path| {
@@ -185,7 +175,7 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
185175
try file_info.updateVersion(current_version_str, new_version_str);
186176
try file_info.write();
187177

188-
try updated_files.append(allocator, try allocator.dupe(u8, file_path));
178+
try updated_files.append(try allocator.dupe(u8, file_path));
189179
}
190180

191181
// Execute custom commands
@@ -203,7 +193,7 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
203193
defer allocator.free(result.stdout);
204194
defer allocator.free(result.stderr);
205195

206-
if (!termSuccess(result.term)) {
196+
if (result.term.Exited != 0) {
207197
std.debug.print("Command failed: {s}\n", .{result.stderr});
208198
return error.CommandFailed;
209199
}
@@ -290,7 +280,7 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
290280
return BumpResult{
291281
.old_version = try allocator.dupe(u8, current_version_str),
292282
.new_version = try allocator.dupe(u8, new_version_str),
293-
.files_updated = try updated_files.toOwnedSlice(allocator),
283+
.files_updated = try updated_files.toOwnedSlice(),
294284
.allocator = allocator,
295285
};
296286
}

src/cli.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ pub fn parseArgs(allocator: Allocator) !CliArgs {
1919
defer args.deinit();
2020

2121
var result = CliArgs{};
22-
var files: std.ArrayList([]const u8) = .empty;
23-
defer files.deinit(allocator);
22+
var files = std.ArrayList([]const u8).init(allocator);
23+
defer files.deinit();
2424

25-
var execute_cmds: std.ArrayList([]const u8) = .empty;
26-
defer execute_cmds.deinit(allocator);
25+
var execute_cmds = std.ArrayList([]const u8).init(allocator);
26+
defer execute_cmds.deinit();
2727

2828
// Skip program name
2929
_ = args.skip();
@@ -175,7 +175,7 @@ pub fn parseArgs(allocator: Allocator) !CliArgs {
175175

176176
if (std.mem.eql(u8, arg, "--execute") or std.mem.eql(u8, arg, "-x")) {
177177
const value = args.next() orelse return error.MissingValue;
178-
try execute_cmds.append(allocator, try allocator.dupe(u8, value));
178+
try execute_cmds.append(try allocator.dupe(u8, value));
179179
continue;
180180
}
181181

@@ -184,7 +184,7 @@ pub fn parseArgs(allocator: Allocator) !CliArgs {
184184
var file_iter = std.mem.splitScalar(u8, value, ',');
185185
while (file_iter.next()) |file| {
186186
const trimmed = std.mem.trim(u8, file, &std.ascii.whitespace);
187-
try files.append(allocator, try allocator.dupe(u8, trimmed));
187+
try files.append(try allocator.dupe(u8, trimmed));
188188
}
189189
continue;
190190
}
@@ -195,19 +195,19 @@ pub fn parseArgs(allocator: Allocator) !CliArgs {
195195
result.release = try allocator.dupe(u8, arg);
196196
} else {
197197
// Additional positional arguments are files
198-
try files.append(allocator, try allocator.dupe(u8, arg));
198+
try files.append(try allocator.dupe(u8, arg));
199199
}
200200
}
201201
}
202202

203203
// Set execute commands if any
204204
if (execute_cmds.items.len > 0) {
205-
result.config.execute = try execute_cmds.toOwnedSlice(allocator);
205+
result.config.execute = try execute_cmds.toOwnedSlice();
206206
}
207207

208208
// Set files if any
209209
if (files.items.len > 0) {
210-
result.config.files = try files.toOwnedSlice(allocator);
210+
result.config.files = try files.toOwnedSlice();
211211
}
212212

213213
return result;

src/files.zig

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const FileType = enum {
3838

3939
pub fn isTomlFile(self: FileType) bool {
4040
return self == .cargo_toml or self == .pyproject_toml or
41-
self == .ion_toml or self == .generic_toml;
41+
self == .ion_toml or self == .generic_toml;
4242
}
4343
};
4444

@@ -130,17 +130,17 @@ fn updateVersionInJson(allocator: Allocator, content: []const u8, old_version: [
130130
try obj.put("version", .{ .string = version_str });
131131

132132
// Serialize back to JSON with pretty printing
133-
var output: std.ArrayList(u8) = .empty;
134-
defer output.deinit(allocator);
133+
var output = std.ArrayList(u8).init(allocator);
134+
defer output.deinit();
135135

136136
try std.json.stringify(root, .{
137137
.whitespace = .indent_2,
138-
}, output.writer(allocator));
138+
}, output.writer());
139139

140140
// Add newline at end
141-
try output.append(allocator, '\n');
141+
try output.append('\n');
142142

143-
return try output.toOwnedSlice(allocator);
143+
return try output.toOwnedSlice();
144144
}
145145

146146
fn findVersionInToml(allocator: Allocator, content: []const u8) !?[]u8 {
@@ -174,8 +174,8 @@ fn findVersionInToml(allocator: Allocator, content: []const u8) !?[]u8 {
174174
fn updateVersionInToml(allocator: Allocator, content: []const u8, old_version: []const u8, new_version: []const u8) ![]u8 {
175175
_ = old_version;
176176

177-
var output: std.ArrayList(u8) = .empty;
178-
defer output.deinit(allocator);
177+
var output = std.ArrayList(u8).init(allocator);
178+
defer output.deinit();
179179

180180
var lines = std.mem.splitScalar(u8, content, '\n');
181181
var line_index: usize = 0;
@@ -186,38 +186,36 @@ fn updateVersionInToml(allocator: Allocator, content: []const u8, old_version: [
186186
if (std.mem.startsWith(u8, trimmed, "version")) {
187187
// Check if this is a version field assignment
188188
const eq_index = std.mem.indexOfScalar(u8, trimmed, '=') orelse {
189-
try output.appendSlice(allocator, line);
190-
if (lines.rest().len > 0) try output.append(allocator, '\n');
189+
try output.appendSlice(line);
190+
if (lines.rest().len > 0) try output.append('\n');
191191
continue;
192192
};
193193

194194
const value_part = std.mem.trim(u8, trimmed[eq_index + 1 ..], &std.ascii.whitespace);
195195
if (value_part.len >= 2 and (value_part[0] == '"' or value_part[0] == '\'')) {
196196
// This is a version field, replace it
197197
const leading_space = std.mem.indexOfScalar(u8, line, 'v') orelse 0;
198-
try output.appendSlice(allocator, line[0..leading_space]);
199-
const replacement = try std.fmt.allocPrint(allocator, "version = \"{s}\"", .{new_version});
200-
defer allocator.free(replacement);
201-
try output.appendSlice(allocator, replacement);
198+
try output.appendSlice(line[0..leading_space]);
199+
try output.writer().print("version = \"{s}\"", .{new_version});
202200
} else {
203-
try output.appendSlice(allocator, line);
201+
try output.appendSlice(line);
204202
}
205203
} else {
206-
try output.appendSlice(allocator, line);
204+
try output.appendSlice(line);
207205
}
208206

209-
if (lines.rest().len > 0) try output.append(allocator, '\n');
207+
if (lines.rest().len > 0) try output.append('\n');
210208
}
211209

212-
return try output.toOwnedSlice(allocator);
210+
return try output.toOwnedSlice();
213211
}
214212

215213
fn findVersionInText(allocator: Allocator, content: []const u8) !?[]u8 {
216214
// Look for semantic version patterns in text
217215
// Pattern: \bX.Y.Z\b (word boundaries)
218216
const semver_pattern = std.mem.indexOf(u8, content, "0.") orelse
219-
std.mem.indexOf(u8, content, "1.") orelse
220-
return null;
217+
std.mem.indexOf(u8, content, "1.") orelse
218+
return null;
221219

222220
// Extract the version starting from this position
223221
var end = semver_pattern;
@@ -240,8 +238,8 @@ fn findVersionInText(allocator: Allocator, content: []const u8) !?[]u8 {
240238

241239
fn updateVersionInText(allocator: Allocator, content: []const u8, old_version: []const u8, new_version: []const u8) ![]u8 {
242240
// Simple find and replace with word boundary consideration
243-
var output: std.ArrayList(u8) = .empty;
244-
defer output.deinit(allocator);
241+
var output = std.ArrayList(u8).init(allocator);
242+
defer output.deinit();
245243

246244
var pos: usize = 0;
247245
while (pos < content.len) {
@@ -258,20 +256,20 @@ fn updateVersionInText(allocator: Allocator, content: []const u8, old_version: [
258256

259257
// Only replace if we have word boundaries on both sides
260258
if (has_boundary_before and has_boundary_after) {
261-
try output.appendSlice(allocator, content[pos..abs_index]);
262-
try output.appendSlice(allocator, new_version);
259+
try output.appendSlice(content[pos..abs_index]);
260+
try output.appendSlice(new_version);
263261
pos = end_index;
264262
} else {
265-
try output.appendSlice(allocator, content[pos .. abs_index + 1]);
263+
try output.appendSlice(content[pos .. abs_index + 1]);
266264
pos = abs_index + 1;
267265
}
268266
} else {
269-
try output.appendSlice(allocator, remaining);
267+
try output.appendSlice(remaining);
270268
break;
271269
}
272270
}
273271

274-
return try output.toOwnedSlice(allocator);
272+
return try output.toOwnedSlice();
275273
}
276274

277275
fn isVersionChar(c: u8) bool {
@@ -281,12 +279,12 @@ fn isVersionChar(c: u8) bool {
281279
pub fn findFiles(allocator: Allocator, dir_path: []const u8, recursive: bool, pattern: ?[]const u8) ![][]u8 {
282280
_ = pattern;
283281

284-
var files: std.ArrayList([]u8) = .empty;
282+
var files = std.ArrayList([]u8).init(allocator);
285283
errdefer {
286284
for (files.items) |file| {
287285
allocator.free(file);
288286
}
289-
files.deinit(allocator);
287+
files.deinit();
290288
}
291289

292290
if (recursive) {
@@ -297,13 +295,13 @@ pub fn findFiles(allocator: Allocator, dir_path: []const u8, recursive: bool, pa
297295
defer allocator.free(package_json_path);
298296

299297
std.fs.cwd().access(package_json_path, .{}) catch {
300-
return files.toOwnedSlice(allocator);
298+
return files.toOwnedSlice();
301299
};
302300

303-
try files.append(allocator, try allocator.dupe(u8, package_json_path));
301+
try files.append(try allocator.dupe(u8, package_json_path));
304302
}
305303

306-
return try files.toOwnedSlice(allocator);
304+
return try files.toOwnedSlice();
307305
}
308306

309307
fn findFilesRecursive(allocator: Allocator, files: *std.ArrayList([]u8), dir_path: []const u8) !void {
@@ -334,7 +332,7 @@ fn findFilesRecursive(allocator: Allocator, files: *std.ArrayList([]u8), dir_pat
334332
.file => {
335333
const file_type = FileType.fromPath(entry.name);
336334
if (file_type == .package_json or file_type.isTomlFile()) {
337-
try files.append(allocator, try allocator.dupe(u8, full_path));
335+
try files.append(try allocator.dupe(u8, full_path));
338336
}
339337
},
340338
else => {},

0 commit comments

Comments
 (0)