From 4dd206a5a3a32e23e05c0842ce4db7a108de4d5f Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 14 Aug 2025 17:50:42 +0200 Subject: Refactor shared eval function parameters into a CommandContext struct. --- src/cmd/time.zig | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/cmd/time.zig') diff --git a/src/cmd/time.zig b/src/cmd/time.zig index bd03cfa..c30ca47 100644 --- a/src/cmd/time.zig +++ b/src/cmd/time.zig @@ -4,13 +4,11 @@ const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; -const OutputCapture = types.OutputCapture; -const InputSource = types.InputSource; +const CommandContext = types.CommandContext; pub const Time = struct { - pub fn eval(time: Time, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(time: Time, ctx: CommandContext) !CommandStatus { _ = time; - _ = input_source; const timestamp = std.time.timestamp(); const epoch_seconds = @as(u64, @intCast(timestamp)); @@ -19,9 +17,9 @@ pub const Time = struct { const minutes = (day_seconds % std.time.s_per_hour) / std.time.s_per_min; const seconds = day_seconds % std.time.s_per_min; - const output = try std.fmt.allocPrint(allocator, "Current time is {d:0>2}:{d:0>2}:{d:0>2}\n", .{ hours, minutes, seconds }); - defer allocator.free(output); - if (output_capture) |capture| { + const output = try std.fmt.allocPrint(ctx.allocator, "Current time is {d:0>2}:{d:0>2}:{d:0>2}\n", .{ hours, minutes, seconds }); + defer ctx.allocator.free(output); + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); -- cgit v1.2.1