From 37ec6df5afb6568dec38ca1c6ad03bd845801f02 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 7 May 2024 20:32:46 -0400 Subject: [PATCH] fix(BREAKING): move `.resolve_command_path` to `ShellState` --- src/shell/commands/mod.rs | 17 ----------------- src/shell/execute.rs | 2 +- src/shell/test.rs | 5 ++++- src/shell/types.rs | 16 +++++++++++++++- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/shell/commands/mod.rs b/src/shell/commands/mod.rs index 453590d..028392c 100644 --- a/src/shell/commands/mod.rs +++ b/src/shell/commands/mod.rs @@ -17,7 +17,6 @@ mod unset; mod xargs; use std::collections::HashMap; -use std::path::PathBuf; use std::rc::Rc; use futures::future::LocalBoxFuture; @@ -117,22 +116,6 @@ pub struct ShellCommandContext { Box FutureExecuteResult>, } -impl ShellCommandContext { - /// Resolves the path to a command from the current working directory. - /// - /// Does not take injected custom commands into account. - pub fn resolve_command_path( - &self, - command_name: &str, - ) -> Result { - super::command::resolve_command_path( - command_name, - self.state.cwd(), - &self.state, - ) - } -} - pub trait ShellCommand { fn execute( &self, diff --git a/src/shell/execute.rs b/src/shell/execute.rs index ce9754a..5eeb88f 100644 --- a/src/shell/execute.rs +++ b/src/shell/execute.rs @@ -670,7 +670,7 @@ fn execute_command_args( ) }), }; - match command_context.state.resolve_command(&command_name) { + match command_context.state.resolve_custom_command(&command_name) { Some(command) => command.execute(command_context), None => execute_unresolved_command_name( UnresolvedCommandName { diff --git a/src/shell/test.rs b/src/shell/test.rs index 6bd7b36..669e986 100644 --- a/src/shell/test.rs +++ b/src/shell/test.rs @@ -1164,7 +1164,10 @@ async fn custom_command_resolve_command_path() { "custom_which", Box::new(|mut context| { async move { - let path = context.resolve_command_path(&context.args[0]).unwrap(); + let path = context + .state + .resolve_command_path(&context.args[0]) + .unwrap(); let _ = context.stdout.write_line(&path.to_string_lossy()); ExecuteResult::from_exit_code(0) } diff --git a/src/shell/types.rs b/src/shell/types.rs index 4694730..f78ba66 100644 --- a/src/shell/types.rs +++ b/src/shell/types.rs @@ -135,11 +135,25 @@ impl ShellState { &self.token } - pub fn resolve_command(&self, name: &str) -> Option> { + /// Resolves a custom command that was injected. + pub fn resolve_custom_command( + &self, + name: &str, + ) -> Option> { // uses an Rc to allow resolving a command without borrowing from self self.commands.get(name).cloned() } + /// Resolves the path to a command from the current working directory. + /// + /// Does not take injected custom commands into account. + pub fn resolve_command_path( + &self, + command_name: &str, + ) -> Result { + super::command::resolve_command_path(command_name, self.cwd(), self) + } + pub fn with_child_token(&self) -> ShellState { let mut state = self.clone(); state.token = self.token.child_token();