Skip to content

Commit 78b199c

Browse files
committed
chore: wip
1 parent d0560db commit 78b199c

21 files changed

+199
-197
lines changed

packages/zig/src/cli.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ pub const CLI = struct {
3333
return CLI{
3434
.allocator = allocator,
3535
.name = try allocator.dupe(u8, name),
36-
.commands = std.ArrayList(Command).init(allocator),
36+
.commands = .{},
3737
.global_command = global_cmd,
3838
.matched_command = null,
3939
.matched_command_name = null,
4040
.raw_args = &[_][]const u8{},
41-
.args = std.ArrayList([]const u8).init(allocator),
41+
.args = .{},
4242
.options = std.StringHashMap([]const u8).init(allocator),
4343
.show_help_on_exit = false,
4444
.show_version_on_exit = false,
@@ -68,7 +68,7 @@ pub const CLI = struct {
6868
pub fn command(self: *CLI, raw_name: []const u8, description: []const u8, config: types.CommandConfig) !*Command {
6969
var cmd = try Command.init(self.allocator, raw_name, description, config);
7070
cmd.cli = @ptrCast(self);
71-
try self.commands.append(cmd);
71+
try self.commands.append(self.allocator, cmd);
7272

7373
// Return pointer to the command in the ArrayList
7474
return &self.commands.items[self.commands.items.len - 1];
@@ -139,7 +139,7 @@ pub const CLI = struct {
139139
// Copy args (skipping command name)
140140
self.args.clearRetainingCapacity();
141141
for (parsed.args.items[1..]) |arg| {
142-
try self.args.append(try self.allocator.dupe(u8, arg));
142+
try self.args.append(self.allocator, try self.allocator.dupe(u8, arg));
143143
}
144144

145145
// Copy options
@@ -169,7 +169,7 @@ pub const CLI = struct {
169169

170170
self.args.clearRetainingCapacity();
171171
for (parsed.args.items) |arg| {
172-
try self.args.append(try self.allocator.dupe(u8, arg));
172+
try self.args.append(self.allocator, try self.allocator.dupe(u8, arg));
173173
}
174174

175175
self.options.clearRetainingCapacity();
@@ -211,19 +211,19 @@ pub const CLI = struct {
211211

212212
/// Parse command line arguments
213213
fn parseArgs(self: *CLI, argv: []const []const u8, cmd: ?*Command) !types.ParsedArgv {
214-
var parsed_args = std.ArrayList([]const u8).init(self.allocator);
214+
var parsed_args: std.ArrayList([]const u8) = .{};
215215
var parsed_options = std.StringHashMap([]const u8).init(self.allocator);
216216

217217
// Collect all options (global + command-specific)
218-
var all_options = std.ArrayList(*const Option).init(self.allocator);
218+
var all_options: std.ArrayList(*const Option) = .{};
219219
defer all_options.deinit();
220220

221221
for (self.global_command.options.items) |*opt| {
222-
try all_options.append(opt);
222+
try all_options.append(self.allocator, opt);
223223
}
224224
if (cmd) |matched_cmd| {
225225
for (matched_cmd.options.items) |*opt| {
226-
try all_options.append(opt);
226+
try all_options.append(self.allocator, opt);
227227
}
228228
}
229229

@@ -287,7 +287,7 @@ pub const CLI = struct {
287287
}
288288
} else {
289289
// Regular argument
290-
try parsed_args.append(try self.allocator.dupe(u8, arg));
290+
try parsed_args.append(self.allocator, try self.allocator.dupe(u8, arg));
291291
}
292292
}
293293

packages/zig/src/command.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ pub const Command = struct {
5353
.description = try allocator.dupe(u8, description),
5454
.name = name,
5555
.args = args,
56-
.options = std.ArrayList(Option).init(allocator),
57-
.alias_names = std.ArrayList([]const u8).init(allocator),
56+
.options = .{},
57+
.alias_names = .{},
5858
.command_action = null,
5959
.usage_text = null,
6060
.version_number = null,
61-
.examples = std.ArrayList(types.CommandExample).init(allocator),
61+
.examples = .{},
6262
.help_callback = null,
6363
.config = config,
6464
.cli = null,
@@ -125,19 +125,19 @@ pub const Command = struct {
125125

126126
/// Add an example
127127
pub fn example(self: *Command, ex: types.CommandExample) !void {
128-
try self.examples.append(ex);
128+
try self.examples.append(self.allocator, ex);
129129
}
130130

131131
/// Add an option to the command
132132
pub fn option(self: *Command, raw_name: []const u8, description: []const u8, config: types.OptionConfig) !void {
133133
const opt = try Option.init(self.allocator, raw_name, description, config);
134-
try self.options.append(opt);
134+
try self.options.append(self.allocator, opt);
135135
}
136136

137137
/// Add an alias for the command
138138
pub fn alias(self: *Command, name: []const u8) !void {
139139
const alias_copy = try self.allocator.dupe(u8, name);
140-
try self.alias_names.append(alias_copy);
140+
try self.alias_names.append(self.allocator, alias_copy);
141141
}
142142

143143
/// Set the action callback

packages/zig/src/completion.zig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub fn generateCompletion(allocator: std.mem.Allocator, cli: *const CLI, shell:
2222

2323
/// Generate Bash completion script
2424
fn generateBash(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
25-
var result = std.ArrayList(u8).init(allocator);
26-
defer result.deinit();
25+
var result: std.ArrayList(u8) = .{};
26+
defer result.deinit(allocator);
2727

2828
const writer = result.writer();
2929

@@ -65,13 +65,13 @@ fn generateBash(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
6565
try writer.print("}}\n\n", .{});
6666
try writer.print("complete -F _{s} {s}\n", .{ cli.name, cli.name });
6767

68-
return try result.toOwnedSlice();
68+
return try result.toOwnedSlice(allocator);
6969
}
7070

7171
/// Generate Zsh completion script
7272
fn generateZsh(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
73-
var result = std.ArrayList(u8).init(allocator);
74-
defer result.deinit();
73+
var result: std.ArrayList(u8) = .{};
74+
defer result.deinit(allocator);
7575

7676
const writer = result.writer();
7777

@@ -109,13 +109,13 @@ fn generateZsh(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
109109
try writer.print("}}\n\n", .{});
110110
try writer.print("_{s} \"$@\"\n", .{cli.name});
111111

112-
return try result.toOwnedSlice();
112+
return try result.toOwnedSlice(allocator);
113113
}
114114

115115
/// Generate Fish completion script
116116
fn generateFish(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
117-
var result = std.ArrayList(u8).init(allocator);
118-
defer result.deinit();
117+
var result: std.ArrayList(u8) = .{};
118+
defer result.deinit(allocator);
119119

120120
const writer = result.writer();
121121

@@ -129,13 +129,13 @@ fn generateFish(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
129129
try writer.print("complete -c {s} -f -a \"{s}\" -d \"{s}\"\n", .{ cli.name, cmd.name, cmd.description });
130130
}
131131

132-
return try result.toOwnedSlice();
132+
return try result.toOwnedSlice(allocator);
133133
}
134134

135135
/// Generate PowerShell completion script
136136
fn generatePowerShell(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8 {
137-
var result = std.ArrayList(u8).init(allocator);
138-
defer result.deinit();
137+
var result: std.ArrayList(u8) = .{};
138+
defer result.deinit(allocator);
139139

140140
const writer = result.writer();
141141

@@ -151,7 +151,7 @@ fn generatePowerShell(allocator: std.mem.Allocator, cli: *const CLI) ![]const u8
151151
try writer.print(" $commands | Where-Object {{ $_.CompletionText -like \"$wordToComplete*\" }}\n", .{});
152152
try writer.print("}}\n", .{});
153153

154-
return try result.toOwnedSlice();
154+
return try result.toOwnedSlice(allocator);
155155
}
156156

157157
test "bash completion generation" {

packages/zig/src/events.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub const EventEmitter = struct {
2626
var iter = self.listeners.iterator();
2727
while (iter.next()) |entry| {
2828
self.allocator.free(entry.key_ptr.*);
29-
entry.value_ptr.deinit();
29+
entry.value_ptr.deinit(self.allocator);
3030
}
3131
self.listeners.deinit();
3232
}
@@ -41,10 +41,10 @@ pub const EventEmitter = struct {
4141

4242
var result = try self.listeners.getOrPut(key);
4343
if (!result.found_existing) {
44-
result.value_ptr.* = std.ArrayList(Listener).init(self.allocator);
44+
result.value_ptr.* = .{};
4545
}
4646

47-
try result.value_ptr.append(.{
47+
try result.value_ptr.append(self.allocator, .{
4848
.callback = callback,
4949
.once = false,
5050
});
@@ -60,10 +60,10 @@ pub const EventEmitter = struct {
6060

6161
var result = try self.listeners.getOrPut(key);
6262
if (!result.found_existing) {
63-
result.value_ptr.* = std.ArrayList(Listener).init(self.allocator);
63+
result.value_ptr.* = .{};
6464
}
6565

66-
try result.value_ptr.append(.{
66+
try result.value_ptr.append(self.allocator, .{
6767
.callback = callback,
6868
.once = true,
6969
});

packages/zig/src/log.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub const LogOptions = struct {
1111

1212
/// Process markdown-style italic text (_text_)
1313
fn processMarkdown(allocator: std.mem.Allocator, text: []const u8) ![]const u8 {
14-
var result = std.ArrayList(u8).init(allocator);
15-
errdefer result.deinit();
14+
var result: std.ArrayList(u8) = .{};
15+
errdefer result.deinit(allocator);
1616

1717
var i: usize = 0;
1818
var in_italic = false;
@@ -21,24 +21,24 @@ fn processMarkdown(allocator: std.mem.Allocator, text: []const u8) ![]const u8 {
2121
if (text[i] == '_' and i + 1 < text.len and text[i + 1] != ' ') {
2222
// Toggle italic
2323
if (in_italic) {
24-
try result.appendSlice(style.codes.italic.close);
24+
try result.appendSlice(allocator, style.codes.italic.close);
2525
} else {
26-
try result.appendSlice(style.codes.italic.open);
26+
try result.appendSlice(allocator, style.codes.italic.open);
2727
}
2828
in_italic = !in_italic;
2929
i += 1;
3030
} else {
31-
try result.append(text[i]);
31+
try result.append(allocator, text[i]);
3232
i += 1;
3333
}
3434
}
3535

3636
// Close italic if still open
3737
if (in_italic) {
38-
try result.appendSlice(style.codes.italic.close);
38+
try result.appendSlice(allocator, style.codes.italic.close);
3939
}
4040

41-
return result.toOwnedSlice();
41+
return result.toOwnedSlice(allocator);
4242
}
4343

4444
/// Generic log message with custom symbol and color
@@ -50,11 +50,11 @@ pub fn message(allocator: std.mem.Allocator, text: []const u8, options: LogOptio
5050

5151
const symbol = options.symbol orelse "•";
5252

53-
var spacing = std.ArrayList(u8).init(allocator);
53+
var spacing: std.ArrayList(u8) = .{};
5454
defer spacing.deinit();
5555
var i: usize = 0;
5656
while (i < options.spacing) : (i += 1) {
57-
try spacing.append(' ');
57+
try spacing.append(allocator, ' ');
5858
}
5959

6060
if (options.color) |color| {
@@ -138,12 +138,12 @@ pub fn intro(allocator: std.mem.Allocator, text: []const u8) !void {
138138
const border_len = if (text_len + 4 < term_width) text_len + 4 else term_width;
139139

140140
// Create border
141-
var border = std.ArrayList(u8).init(allocator);
141+
var border: std.ArrayList(u8) = .{};
142142
defer border.deinit();
143143

144144
var i: usize = 0;
145145
while (i < border_len - 2) : (i += 1) {
146-
try border.appendSlice(border_char);
146+
try border.appendSlice(allocator, border_char);
147147
}
148148

149149
const border_styled = try style.dim(allocator, border.items);
@@ -177,12 +177,12 @@ pub fn outro(allocator: std.mem.Allocator, text: []const u8) !void {
177177
const border_len = if (text_len + 4 < term_width) text_len + 4 else term_width;
178178

179179
// Create border
180-
var border = std.ArrayList(u8).init(allocator);
180+
var border: std.ArrayList(u8) = .{};
181181
defer border.deinit();
182182

183183
var i: usize = 0;
184184
while (i < border_len - 2) : (i += 1) {
185-
try border.appendSlice(border_char);
185+
try border.appendSlice(allocator, border_char);
186186
}
187187

188188
const border_styled = try style.dim(allocator, border.items);

packages/zig/src/middleware.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ pub const MiddlewareChain = struct {
5656
pub fn init(allocator: std.mem.Allocator) MiddlewareChain {
5757
return MiddlewareChain{
5858
.allocator = allocator,
59-
.middlewares = std.ArrayList(MiddlewareFn).init(allocator),
59+
.middlewares = .{},
6060
};
6161
}
6262

6363
pub fn deinit(self: *MiddlewareChain) void {
64-
self.middlewares.deinit();
64+
self.middlewares.deinit(self.allocator);
6565
}
6666

6767
/// Add middleware to the chain
6868
pub fn use(self: *MiddlewareChain, middleware: MiddlewareFn) !void {
69-
try self.middlewares.append(middleware);
69+
try self.middlewares.append(self.allocator, middleware);
7070
}
7171

7272
/// Execute all middlewares in order
@@ -123,12 +123,12 @@ pub const RateLimiter = struct {
123123
.allocator = allocator,
124124
.max_requests = max_requests,
125125
.window_ms = window_ms,
126-
.requests = std.ArrayList(i64).init(allocator),
126+
.requests = .{},
127127
};
128128
}
129129

130130
pub fn deinit(self: *RateLimiter) void {
131-
self.requests.deinit();
131+
self.requests.deinit(self.allocator);
132132
}
133133

134134
pub fn check(self: *RateLimiter) !bool {
@@ -149,7 +149,7 @@ pub const RateLimiter = struct {
149149
return false;
150150
}
151151

152-
try self.requests.append(now);
152+
try self.requests.append(self.allocator, now);
153153
return true;
154154
}
155155
};

packages/zig/src/option.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub const Option = struct {
3232
.raw_name = try allocator.dupe(u8, raw_name),
3333
.description = try allocator.dupe(u8, description),
3434
.name = undefined,
35-
.names = std.ArrayList([]const u8).init(allocator),
35+
.names = .{},
3636
.is_boolean = false,
3737
.required = null,
3838
.config = config,
@@ -63,7 +63,7 @@ pub const Option = struct {
6363
}
6464

6565
const camelcased = try utils.camelcaseOptionName(allocator, trimmed);
66-
try opt.names.append(camelcased);
66+
try opt.names.append(allocator, camelcased);
6767
}
6868

6969
// Sort names by length

packages/zig/src/prompts.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ pub fn multiSelect(allocator: std.mem.Allocator, options: MultiSelectOptions) ![
217217
return multiSelect(allocator, options);
218218
}
219219

220-
var result = std.ArrayList([]const u8).init(allocator);
221-
errdefer result.deinit();
220+
var result: std.ArrayList([]const u8) = .{};
221+
errdefer result.deinit(allocator);
222222

223223
var iter = std.mem.splitSequence(u8, trimmed, " ");
224224
while (iter.next()) |num_str| {
@@ -241,7 +241,7 @@ pub fn multiSelect(allocator: std.mem.Allocator, options: MultiSelectOptions) ![
241241
}
242242

243243
const value = try allocator.dupe(u8, options.options[index - 1].value);
244-
try result.append(value);
244+
try result.append(allocator, value);
245245
}
246246

247247
if (result.items.len == 0 and options.required) {
@@ -252,7 +252,7 @@ pub fn multiSelect(allocator: std.mem.Allocator, options: MultiSelectOptions) ![
252252
return multiSelect(allocator, options);
253253
}
254254

255-
return try result.toOwnedSlice();
255+
return try result.toOwnedSlice(allocator);
256256
}
257257

258258
/// Password prompt (masked input)

0 commit comments

Comments
 (0)