use std::path::{Path, PathBuf}; use brush_core::builtins; use clap::Parser; /// Evaluate the provided script in the current shell environment. #[derive(Parser)] pub(crate) struct DotCommand { /// Path to the script to evaluate. script_path: String, /// Any arguments to be passed as positional parameters to the script. #[arg(trailing_var_arg = true, allow_hyphen_values = true)] script_args: Vec, } impl builtins::Command for DotCommand { type Error = brush_core::Error; async fn execute( &self, context: brush_core::ExecutionContext<'_, SE>, ) -> Result { // TODO(dot): Handle trap inheritance. // hydrashell: POSIX requires `.` to search PATH when its operand has no slash. // Git's `git-subtree` relies on this with `. git-sh-setup`; treating the // operand as cwd-relative leaves `require_work_tree` undefined. let script_path = Path::new(&self.script_path); let resolved_path = if context.shell.options().source_builtin_searches_path && !self.script_path.chars().any(std::path::is_separator) { context .shell .env_str("PATH") .and_then(|path| { std::env::split_paths(path.as_ref()) .map(|dir| dir.join(script_path)) .find(|candidate| candidate.is_file()) }) .unwrap_or_else(|| PathBuf::from(script_path)) } else { PathBuf::from(script_path) }; context .shell .source_script(&resolved_path, self.script_args.iter(), &context.params) .await } }