diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-14 20:01:07 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-14 20:01:07 +0200 |
commit | af64a8fb6f8d0651d1881166d79fccbc2c2872f3 (patch) | |
tree | 3dd5ddaf889acdfd30393a762482ccba6d208e53 /src | |
parent | 4dd206a5a3a32e23e05c0842ce4db7a108de4d5f (diff) |
CommandContext: Remove execute_command.
It was not properly typeable and it was null most of the time.
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/lib/types.zig | 17 | ||||
-rw-r--r-- | src/cmd/pipe.zig | 3 | ||||
-rw-r--r-- | src/cmd/redirect.zig | 3 | ||||
-rw-r--r-- | src/eval.zig | 6 |
4 files changed, 4 insertions, 25 deletions
diff --git a/src/cmd/lib/types.zig b/src/cmd/lib/types.zig index 2d96295..5990511 100644 --- a/src/cmd/lib/types.zig +++ b/src/cmd/lib/types.zig @@ -67,28 +67,11 @@ pub const CommandContext = struct { output_capture: ?*OutputCapture, input_source: ?*InputSource, - // The real type is: - // - // const ExecuteCommandFn = *const fn (Command, Allocator, ?*OutputCapture, ?*InputSource) anyerror!CommandStatus; - // - // But Command is defined in ../cmd.zig, so we can't write it. - execute_command: ?*const anyopaque, // Will be cast to the appropriate function type when used - pub fn init(allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) CommandContext { return CommandContext{ .allocator = allocator, .output_capture = output_capture, .input_source = input_source, - .execute_command = null, - }; - } - - pub fn with_executor(allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource, execute_command: anytype) CommandContext { - return CommandContext{ - .allocator = allocator, - .output_capture = output_capture, - .input_source = input_source, - .execute_command = @ptrCast(&execute_command), }; } }; diff --git a/src/cmd/pipe.zig b/src/cmd/pipe.zig index f97561a..ad0d0e4 100644 --- a/src/cmd/pipe.zig +++ b/src/cmd/pipe.zig @@ -18,9 +18,8 @@ pub const PipeCommand = struct { left: *Command, right: *Command, - pub fn eval(pipe: PipeCommand, ctx: CommandContext) !CommandStatus { + pub fn eval(pipe: PipeCommand, ctx: CommandContext, executeCommandWithOutput: ExecuteCommandFn) !CommandStatus { // Cast the execute function back to its proper type - const executeCommandWithOutput: ExecuteCommandFn = @ptrCast(@alignCast(ctx.execute_command.?)); const allocator = ctx.allocator; const output_capture = ctx.output_capture; diff --git a/src/cmd/redirect.zig b/src/cmd/redirect.zig index 4cba259..969f6c4 100644 --- a/src/cmd/redirect.zig +++ b/src/cmd/redirect.zig @@ -23,11 +23,10 @@ pub const RedirectCommand = struct { command: *Command, redirects: ArrayList(Redirect), - pub fn eval(redirect: RedirectCommand, ctx: CommandContext) !CommandStatus { + pub fn eval(redirect: RedirectCommand, ctx: CommandContext, executeCommandWithOutput: ExecuteCommandFn) !CommandStatus { _ = ctx.input_source; // Redirect handles its own input source // Cast the execute function back to its proper type - const executeCommandWithOutput: ExecuteCommandFn = @ptrCast(@alignCast(ctx.execute_command.?)); const allocator = ctx.allocator; const output_capture = ctx.output_capture; diff --git a/src/eval.zig b/src/eval.zig index 7aaae4b..3b349e0 100644 --- a/src/eval.zig +++ b/src/eval.zig @@ -128,13 +128,11 @@ pub fn executeCommandWithOutput(command: Command, allocator: Allocator, output_c }, .Redirect => |redirect| { - const ctx_with_executor = CommandContext.with_executor(allocator, output_capture, input_source, executeCommandWithOutput); - return redirect.eval(ctx_with_executor); + return redirect.eval(ctx, executeCommandWithOutput); }, .Pipe => |pipe| { - const ctx_with_executor = CommandContext.with_executor(allocator, output_capture, input_source, executeCommandWithOutput); - return pipe.eval(ctx_with_executor); + return pipe.eval(ctx, executeCommandWithOutput); }, } } |