const std = @import("std"); const Allocator = std.mem.Allocator; const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; const CommandContext = types.CommandContext; const OutputCapture = types.OutputCapture; const InputSource = types.InputSource; const cmd = @import("../cmd.zig"); const Command = cmd.Command; pub const PipeCommand = struct { left: *Command, right: *Command, pub fn eval(pipe: PipeCommand, ctx: CommandContext) !CommandStatus { const execute_command = ctx.execute_command; const allocator = ctx.allocator; // Extract output_capture from the output_writer for pipe logic const output_capture = switch (ctx.output_writer) { .capture => |capture| capture, .stdout => null, }; // Create output capture for the left command var left_output = OutputCapture.init(allocator); defer left_output.deinit(); // Execute the left command and capture its output const left_status = try execute_command(pipe.left.*, allocator, &left_output, null); // If the left command failed, return its status if (left_status != .Code or left_status.Code != 0) { return left_status; } // Create input source from the left command's output const left_output_data = left_output.getContents(); var right_input = InputSource.init(left_output_data); // Execute the right command with the left command's output as input const right_status = try execute_command(pipe.right.*, allocator, output_capture, &right_input); return right_status; } };