mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
ISSUE-1744-Glob support for start command (#1912)
* Possible implementation of globbing for start command * Whoops forgot to remove Error used for debugging * Use string lossy * Run clippy * Pin glob * Better error messages * Remove unneeded comment
This commit is contained in:
parent
ad43ef08e5
commit
ecb67fee40
3 changed files with 35 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2519,6 +2519,7 @@ dependencies = [
|
||||||
name = "nu_plugin_start"
|
name = "nu_plugin_start"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"glob",
|
||||||
"nu-build",
|
"nu-build",
|
||||||
"nu-errors",
|
"nu-errors",
|
||||||
"nu-plugin",
|
"nu-plugin",
|
||||||
|
|
|
@ -16,6 +16,7 @@ nu-source = { path = "../nu-source", version = "0.14.1" }
|
||||||
nu-errors = { path = "../nu-errors", version = "0.14.1" }
|
nu-errors = { path = "../nu-errors", version = "0.14.1" }
|
||||||
url = "2.1.1"
|
url = "2.1.1"
|
||||||
open = "1.4.0"
|
open = "1.4.0"
|
||||||
|
glob = "0.3.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
nu-build = { version = "0.14.1", path = "../nu-build" }
|
nu-build = { version = "0.14.1", path = "../nu-build" }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::CallInfo;
|
use nu_protocol::{CallInfo, Value};
|
||||||
use nu_source::{Tag, Tagged, TaggedItem};
|
use nu_source::{Tag, Tagged, TaggedItem};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -42,13 +42,44 @@ impl Start {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn glob_to_values(&self, value: &Value) -> Result<Vec<Tagged<String>>, 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> {
|
fn parse_filenames(&mut self, call_info: &CallInfo) -> Result<(), ShellError> {
|
||||||
let candidates = match &call_info.args.positional {
|
let candidates = match &call_info.args.positional {
|
||||||
Some(values) => {
|
Some(values) => {
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
for value in values.iter() {
|
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() {
|
if result.is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue