diff options
Diffstat (limited to 'src/cmd/echo.zig')
-rw-r--r-- | src/cmd/echo.zig | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/cmd/echo.zig b/src/cmd/echo.zig index d3ef8b1..4f2731b 100644 --- a/src/cmd/echo.zig +++ b/src/cmd/echo.zig @@ -4,28 +4,23 @@ 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 EchoOff = struct { - pub fn eval(echo_off: EchoOff, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(echo_off: EchoOff, ctx: CommandContext) !CommandStatus { _ = echo_off; - _ = allocator; - _ = output_capture; - _ = input_source; + _ = ctx; return CommandStatus{ .Code = 0 }; } }; pub const EchoOn = struct { - pub fn eval(echo_on: EchoOn, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(echo_on: EchoOn, ctx: CommandContext) !CommandStatus { _ = echo_on; - _ = allocator; - _ = input_source; const output = "ECHO is on\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); @@ -35,13 +30,11 @@ pub const EchoOn = struct { }; pub const EchoPlain = struct { - pub fn eval(echo_plain: EchoPlain, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(echo_plain: EchoPlain, ctx: CommandContext) !CommandStatus { _ = echo_plain; - _ = allocator; - _ = input_source; const output = "ECHO is on\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); @@ -53,12 +46,10 @@ pub const EchoPlain = struct { pub const EchoText = struct { message: []const u8, - pub fn eval(echo_text: EchoText, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { - _ = input_source; - - const output = try std.fmt.allocPrint(allocator, "{s}\n", .{echo_text.message}); - defer allocator.free(output); - if (output_capture) |capture| { + pub fn eval(echo_text: EchoText, ctx: CommandContext) !CommandStatus { + const output = try std.fmt.allocPrint(ctx.allocator, "{s}\n", .{echo_text.message}); + defer ctx.allocator.free(output); + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); |