Skip to content

Commit

Permalink
Merge pull request #27 from tcoratger/new-zig-master
Browse files Browse the repository at this point in the history
new zig update: use `const` instead of `var` when possible
  • Loading branch information
sam701 authored Nov 21, 2023
2 parents 5cad24c + 16c4636 commit f9e099b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const HelpPrinter = struct {
for (command_path) |cmd| {
self.printer.format("{s} ", .{cmd.name});
}
var current_command = command_path[command_path.len - 1];
const current_command = command_path[command_path.len - 1];
self.printer.format("[OPTIONS]\n", .{});
self.printer.printColor(color_clear);

Expand Down Expand Up @@ -81,7 +81,7 @@ const HelpPrinter = struct {
if (current_command.options) |option_list| {
var max_option_width: usize = 0;
for (option_list) |option| {
var w = option.long_name.len + option.value_name.len + 3;
const w = option.long_name.len + option.value_name.len + 3;
max_option_width = @max(max_option_width, w);
}
option_column_width = max_option_width + 3;
Expand Down
2 changes: 1 addition & 1 deletion src/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn Parser(comptime Iterator: type) type {
}

self.ensure_all_required_set(self.current_command());
var args = try self.captured_arguments.toOwnedSlice();
const args = try self.captured_arguments.toOwnedSlice();

if (self.current_command().action) |action| {
return ParseResult{ .action = action, .args = args };
Expand Down
6 changes: 3 additions & 3 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const StringSliceIterator = struct {
};

fn run(app: *command.App, items: []const []const u8) !ParseResult {
var it = StringSliceIterator{
const it = StringSliceIterator{
.items = items,
};

var parser = try Parser(StringSliceIterator).init(app, it, alloc);
var result = try parser.parse();
const result = try parser.parse();
parser.deinit();
return result;
}
Expand Down Expand Up @@ -230,7 +230,7 @@ test "mix positional arguments and options" {
.action = dummy_action,
};

var result = try run(&app, &.{ "cmd", "--bb", "tt", "arg1", "-a", "val", "arg2", "--", "--arg3", "-arg4" });
const result = try run(&app, &.{ "cmd", "--bb", "tt", "arg1", "-a", "val", "arg2", "--", "--arg3", "-arg4" });
defer std.testing.allocator.free(result.args);
try std.testing.expectEqualStrings("val", aav);
try std.testing.expectEqualStrings("tt", bbv);
Expand Down
6 changes: 3 additions & 3 deletions src/value_ref.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const ValueRef = struct {
if (list.list_ptr == null) {
list.list_ptr = try list.vtable.createList(alloc);
}
var value_ptr = try list.vtable.addOne(list.list_ptr.?, alloc);
const value_ptr = try list.vtable.addOne(list.list_ptr.?, alloc);
try self.value_data.value_parser(value_ptr, value);
},
}
Expand Down Expand Up @@ -97,7 +97,7 @@ const ValueList = struct {
const List = std.ArrayListUnmanaged(T);
const gen = struct {
fn createList(alloc: Allocator) anyerror!*anyopaque {
var list = try alloc.create(List);
const list = try alloc.create(List);
list.* = List{};
return list;
}
Expand All @@ -107,7 +107,7 @@ const ValueList = struct {
}
fn finalize(list_ptr: *anyopaque, dest: *anyopaque, alloc: Allocator) anyerror!void {
const list: *List = @alignCast(@ptrCast(list_ptr));
var destSlice: *[]T = @alignCast(@ptrCast(dest));
const destSlice: *[]T = @alignCast(@ptrCast(dest));
destSlice.* = try list.toOwnedSlice(alloc);
alloc.destroy(list);
}
Expand Down

0 comments on commit f9e099b

Please sign in to comment.