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/rename.zig | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/cmd/rename.zig') diff --git a/src/cmd/rename.zig b/src/cmd/rename.zig index 9942f4c..baca001 100644 --- a/src/cmd/rename.zig +++ b/src/cmd/rename.zig @@ -7,21 +7,20 @@ const FileSpec = syntax.FileSpec; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; -const OutputCapture = types.OutputCapture; -const InputSource = types.InputSource; +const CommandContext = types.CommandContext; pub const Rename = struct { from: FileSpec, to: FileSpec, - pub fn eval(rename: Rename, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { - _ = allocator; - _ = input_source; + pub fn eval(rename: Rename, ctx: CommandContext) !CommandStatus { + _ = ctx.allocator; + _ = ctx.input_source; const from_path = switch (rename.from) { .Con, .Lpt1, .Lpt2, .Lpt3, .Prn => { const error_msg = "Cannot rename device\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(error_msg); } else { print("{s}", .{error_msg}); @@ -34,7 +33,7 @@ pub const Rename = struct { const to_path = switch (rename.to) { .Con, .Lpt1, .Lpt2, .Lpt3, .Prn => { const error_msg = "Cannot rename to device\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(error_msg); } else { print("{s}", .{error_msg}); @@ -52,7 +51,7 @@ pub const Rename = struct { error.RenameAcrossMountPoints => "Cannot rename across different drives\n", else => "Cannot rename file\n", }; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(error_msg); } else { print("{s}", .{error_msg}); -- cgit v1.2.1