Expand globs and filepaths (#348)

This commit is contained in:
JT 2021-11-19 08:32:27 +13:00 committed by GitHub
parent adb7eeb740
commit aa7226d5f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

1
Cargo.lock generated
View file

@ -945,6 +945,7 @@ name = "nu-parser"
version = "0.1.0"
dependencies = [
"miette",
"nu-path",
"nu-plugin",
"nu-protocol",
"thiserror",

View file

@ -8,6 +8,7 @@ miette = "3.0.0"
thiserror = "1.0.29"
nu-protocol = { path = "../nu-protocol"}
nu-plugin = { path = "../nu-plugin", optional=true}
nu-path = {path = "../nu-path"}
[features]
plugin = ["nu-plugin"]

View file

@ -1437,9 +1437,11 @@ pub fn parse_filepath(
let bytes = trim_quotes(bytes);
if let Ok(token) = String::from_utf8(bytes.into()) {
let filepath = nu_path::expand_path(token);
let filepath = filepath.to_string_lossy().to_string();
(
Expression {
expr: Expr::Filepath(token),
expr: Expr::Filepath(filepath),
span,
ty: Type::String,
custom_completion: None,
@ -1449,7 +1451,7 @@ pub fn parse_filepath(
} else {
(
garbage(span),
Some(ParseError::Expected("string".into(), span)),
Some(ParseError::Expected("filepath".into(), span)),
)
}
}
@ -1649,9 +1651,12 @@ pub fn parse_glob_pattern(
let bytes = trim_quotes(bytes);
if let Ok(token) = String::from_utf8(bytes.into()) {
let filepath = nu_path::expand_path(token);
let filepath = filepath.to_string_lossy().to_string();
(
Expression {
expr: Expr::GlobPattern(token),
expr: Expr::GlobPattern(filepath),
span,
ty: Type::String,
custom_completion: None,