Skip to content

Commit 39d61c2

Browse files
chrisbbreuerclaude
andcommitted
fix: correct Zig 0.15.1 API usage (PascalCase Term, unmanaged ArrayList)
Use std.fs.File.stdin() instead of std.io.getStdIn(), PascalCase .Exited/.Signal for Child.Term, and unmanaged ArrayList (.empty + allocator params) throughout all source files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d8990bd commit 39d61c2

6 files changed

Lines changed: 175 additions & 147 deletions

File tree

src/bump.zig

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ 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+
3239
pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
3340
const config = options.config;
3441

@@ -39,10 +46,12 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
3946
std.debug.print("Warning: You have uncommitted changes.\n", .{});
4047
if (!config.yes) {
4148
std.debug.print("Continue anyway? (y/N): ", .{});
42-
const stdin = std.io.getStdIn().reader();
49+
const stdin = std.fs.File.stdin();
4350
var buf: [10]u8 = undefined;
44-
const input = try stdin.readUntilDelimiterOrEof(&buf, '\n');
45-
if (input == null or (input.?.len > 0 and input.?[0] != 'y' and input.?[0] != 'Y')) {
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')) {
4655
return error.Cancelled;
4756
}
4857
}
@@ -118,10 +127,11 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
118127
// Confirmation prompt
119128
if (!config.yes and !config.ci) {
120129
std.debug.print("\nWill update {d} file(s). Continue? (Y/n): ", .{files_to_update.len});
121-
const stdin = std.io.getStdIn().reader();
130+
const stdin = std.fs.File.stdin();
122131
var buf: [10]u8 = undefined;
123-
const input = try stdin.readUntilDelimiterOrEof(&buf, '\n');
124-
if (input) |inp| {
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);
125135
if (inp.len > 0 and inp[0] != 'y' and inp[0] != 'Y' and inp[0] != '\r') {
126136
return error.Cancelled;
127137
}
@@ -156,12 +166,12 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
156166
}
157167

158168
// Update all files
159-
var updated_files = std.ArrayList([]const u8).init(allocator);
169+
var updated_files: std.ArrayList([]const u8) = .empty;
160170
errdefer {
161171
for (updated_files.items) |file| {
162172
allocator.free(file);
163173
}
164-
updated_files.deinit();
174+
updated_files.deinit(allocator);
165175
}
166176

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

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

181191
// Execute custom commands
@@ -193,7 +203,7 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
193203
defer allocator.free(result.stdout);
194204
defer allocator.free(result.stderr);
195205

196-
if (result.term.Exited != 0) {
206+
if (!termSuccess(result.term)) {
197207
std.debug.print("Command failed: {s}\n", .{result.stderr});
198208
return error.CommandFailed;
199209
}
@@ -280,7 +290,7 @@ pub fn versionBump(allocator: Allocator, options: BumpOptions) !BumpResult {
280290
return BumpResult{
281291
.old_version = try allocator.dupe(u8, current_version_str),
282292
.new_version = try allocator.dupe(u8, new_version_str),
283-
.files_updated = try updated_files.toOwnedSlice(),
293+
.files_updated = try updated_files.toOwnedSlice(allocator),
284294
.allocator = allocator,
285295
};
286296
}

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).init(allocator);
23-
defer files.deinit();
22+
var files: std.ArrayList([]const u8) = .empty;
23+
defer files.deinit(allocator);
2424

25-
var execute_cmds = std.ArrayList([]const u8).init(allocator);
26-
defer execute_cmds.deinit();
25+
var execute_cmds: std.ArrayList([]const u8) = .empty;
26+
defer execute_cmds.deinit(allocator);
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(try allocator.dupe(u8, value));
178+
try execute_cmds.append(allocator, 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(try allocator.dupe(u8, trimmed));
187+
try files.append(allocator, 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(try allocator.dupe(u8, arg));
198+
try files.append(allocator, 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();
205+
result.config.execute = try execute_cmds.toOwnedSlice(allocator);
206206
}
207207

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

213213
return result;

src/files.zig

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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).init(allocator);
134-
defer output.deinit();
133+
var output: std.ArrayList(u8) = .empty;
134+
defer output.deinit(allocator);
135135

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

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

143-
return try output.toOwnedSlice();
143+
return try output.toOwnedSlice(allocator);
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).init(allocator);
178-
defer output.deinit();
177+
var output: std.ArrayList(u8) = .empty;
178+
defer output.deinit(allocator);
179179

180180
var lines = std.mem.splitScalar(u8, content, '\n');
181181
var line_index: usize = 0;
@@ -186,36 +186,38 @@ 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(line);
190-
if (lines.rest().len > 0) try output.append('\n');
189+
try output.appendSlice(allocator, line);
190+
if (lines.rest().len > 0) try output.append(allocator, '\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(line[0..leading_space]);
199-
try output.writer().print("version = \"{s}\"", .{new_version});
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);
200202
} else {
201-
try output.appendSlice(line);
203+
try output.appendSlice(allocator, line);
202204
}
203205
} else {
204-
try output.appendSlice(line);
206+
try output.appendSlice(allocator, line);
205207
}
206208

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

210-
return try output.toOwnedSlice();
212+
return try output.toOwnedSlice(allocator);
211213
}
212214

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

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

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

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

257259
// Only replace if we have word boundaries on both sides
258260
if (has_boundary_before and has_boundary_after) {
259-
try output.appendSlice(content[pos..abs_index]);
260-
try output.appendSlice(new_version);
261+
try output.appendSlice(allocator, content[pos..abs_index]);
262+
try output.appendSlice(allocator, new_version);
261263
pos = end_index;
262264
} else {
263-
try output.appendSlice(content[pos .. abs_index + 1]);
265+
try output.appendSlice(allocator, content[pos .. abs_index + 1]);
264266
pos = abs_index + 1;
265267
}
266268
} else {
267-
try output.appendSlice(remaining);
269+
try output.appendSlice(allocator, remaining);
268270
break;
269271
}
270272
}
271273

272-
return try output.toOwnedSlice();
274+
return try output.toOwnedSlice(allocator);
273275
}
274276

275277
fn isVersionChar(c: u8) bool {
@@ -279,12 +281,12 @@ fn isVersionChar(c: u8) bool {
279281
pub fn findFiles(allocator: Allocator, dir_path: []const u8, recursive: bool, pattern: ?[]const u8) ![][]u8 {
280282
_ = pattern;
281283

282-
var files = std.ArrayList([]u8).init(allocator);
284+
var files: std.ArrayList([]u8) = .empty;
283285
errdefer {
284286
for (files.items) |file| {
285287
allocator.free(file);
286288
}
287-
files.deinit();
289+
files.deinit(allocator);
288290
}
289291

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

297299
std.fs.cwd().access(package_json_path, .{}) catch {
298-
return files.toOwnedSlice();
300+
return files.toOwnedSlice(allocator);
299301
};
300302

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

304-
return try files.toOwnedSlice();
306+
return try files.toOwnedSlice(allocator);
305307
}
306308

307309
fn findFilesRecursive(allocator: Allocator, files: *std.ArrayList([]u8), dir_path: []const u8) !void {
@@ -332,7 +334,7 @@ fn findFilesRecursive(allocator: Allocator, files: *std.ArrayList([]u8), dir_pat
332334
.file => {
333335
const file_type = FileType.fromPath(entry.name);
334336
if (file_type == .package_json or file_type.isTomlFile()) {
335-
try files.append(try allocator.dupe(u8, full_path));
337+
try files.append(allocator, try allocator.dupe(u8, full_path));
336338
}
337339
},
338340
else => {},

0 commit comments

Comments
 (0)