diff --git a/Cargo.lock b/Cargo.lock index 223338906a..9261c3b122 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2519,6 +2519,7 @@ dependencies = [ name = "nu_plugin_start" version = "0.1.0" dependencies = [ + "glob", "nu-build", "nu-errors", "nu-plugin", diff --git a/crates/nu_plugin_start/Cargo.toml b/crates/nu_plugin_start/Cargo.toml index 09d1c9c95f..1e7eaa8694 100644 --- a/crates/nu_plugin_start/Cargo.toml +++ b/crates/nu_plugin_start/Cargo.toml @@ -16,6 +16,7 @@ nu-source = { path = "../nu-source", version = "0.14.1" } nu-errors = { path = "../nu-errors", version = "0.14.1" } url = "2.1.1" open = "1.4.0" +glob = "0.3.0" [build-dependencies] nu-build = { version = "0.14.1", path = "../nu-build" } diff --git a/crates/nu_plugin_start/src/start.rs b/crates/nu_plugin_start/src/start.rs index 12d9ae0dfb..798367520f 100644 --- a/crates/nu_plugin_start/src/start.rs +++ b/crates/nu_plugin_start/src/start.rs @@ -1,5 +1,5 @@ use nu_errors::ShellError; -use nu_protocol::CallInfo; +use nu_protocol::{CallInfo, Value}; use nu_source::{Tag, Tagged, TaggedItem}; use std::path::Path; @@ -42,13 +42,44 @@ impl Start { } } + fn glob_to_values(&self, value: &Value) -> Result>, ShellError> { + let mut result = vec![]; + match glob::glob(&value.as_string()?) { + Ok(paths) => { + for path_result in paths { + match path_result { + Ok(path) => result + .push(path.to_string_lossy().to_string().tagged(value.tag.clone())), + Err(glob_error) => { + return Err(ShellError::labeled_error( + format!("{}", glob_error), + "glob error", + value.tag.clone(), + )); + } + } + } + } + Err(pattern_error) => { + return Err(ShellError::labeled_error( + format!("{}", pattern_error), + "invalid pattern", + value.tag.clone(), + )) + } + } + + Ok(result) + } + fn parse_filenames(&mut self, call_info: &CallInfo) -> Result<(), ShellError> { let candidates = match &call_info.args.positional { Some(values) => { let mut result = vec![]; for value in values.iter() { - result.push(value.as_string()?.tagged(value.tag.clone())); + let res = self.glob_to_values(value)?; + result.extend(res); } if result.is_empty() {