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" version = "0.1.0"
dependencies = [ dependencies = [
"miette", "miette",
"nu-path",
"nu-plugin", "nu-plugin",
"nu-protocol", "nu-protocol",
"thiserror", "thiserror",

View File

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

View File

@ -1437,9 +1437,11 @@ pub fn parse_filepath(
let bytes = trim_quotes(bytes); let bytes = trim_quotes(bytes);
if let Ok(token) = String::from_utf8(bytes.into()) { 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 { Expression {
expr: Expr::Filepath(token), expr: Expr::Filepath(filepath),
span, span,
ty: Type::String, ty: Type::String,
custom_completion: None, custom_completion: None,
@ -1449,7 +1451,7 @@ pub fn parse_filepath(
} else { } else {
( (
garbage(span), 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); let bytes = trim_quotes(bytes);
if let Ok(token) = String::from_utf8(bytes.into()) { 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 { Expression {
expr: Expr::GlobPattern(token), expr: Expr::GlobPattern(filepath),
span, span,
ty: Type::String, ty: Type::String,
custom_completion: None, custom_completion: None,