Rename the Path and Pattern primitives (#2889)

* Rename the Path primitive to FilePath

* Rename glob pattern also

* more fun

* Fix the Windows path methods
This commit is contained in:
Jonathan Turner 2021-01-08 20:30:41 +13:00 committed by GitHub
parent 2dcb16870b
commit 0e13d9fbaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 146 additions and 131 deletions

View File

@ -134,7 +134,7 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
out!("{}", s);
}
Value {
value: UntaggedValue::Primitive(Primitive::Path(s)),
value: UntaggedValue::Primitive(Primitive::FilePath(s)),
..
} => {
out!("{}", s.display());

View File

@ -23,7 +23,7 @@ impl WholeStreamCommand for Cd {
fn signature(&self) -> Signature {
Signature::build("cd").optional(
"directory",
SyntaxShape::Path,
SyntaxShape::FilePath,
"the directory to change to",
)
}

View File

@ -21,7 +21,7 @@ impl WholeStreamCommand for SubCommand {
fn signature(&self) -> Signature {
Signature::build("config load").required(
"load",
SyntaxShape::Path,
SyntaxShape::FilePath,
"Path to load the config from",
)
}

View File

@ -36,6 +36,6 @@ pub async fn path(args: CommandArgs) -> Result<OutputStream, ShellError> {
let path = config::default_path()?;
Ok(OutputStream::one(ReturnSuccess::value(
UntaggedValue::Primitive(Primitive::Path(path)).into_value(args.call_info.name_tag),
UntaggedValue::Primitive(Primitive::FilePath(path)).into_value(args.call_info.name_tag),
)))
}

View File

@ -22,8 +22,8 @@ impl WholeStreamCommand for Cpy {
fn signature(&self) -> Signature {
Signature::build("cp")
.required("src", SyntaxShape::Pattern, "the place to copy from")
.required("dst", SyntaxShape::Path, "the place to copy to")
.required("src", SyntaxShape::GlobPattern, "the place to copy from")
.required("dst", SyntaxShape::FilePath, "the place to copy to")
.switch(
"recursive",
"copy recursively through subdirectories",

View File

@ -38,7 +38,7 @@ impl WholeStreamCommand for Du {
fn signature(&self) -> Signature {
Signature::build(NAME)
.optional("path", SyntaxShape::Pattern, "starting directory")
.optional("path", SyntaxShape::GlobPattern, "starting directory")
.switch(
"all",
"Output file sizes as well as directory sizes",
@ -51,7 +51,7 @@ impl WholeStreamCommand for Du {
)
.named(
"exclude",
SyntaxShape::Pattern,
SyntaxShape::GlobPattern,
"Exclude these file names",
Some('x'),
)
@ -347,7 +347,7 @@ impl From<DirInfo> for Value {
r.insert(
"path".to_string(),
UntaggedValue::path(d.path).into_value(&d.tag),
UntaggedValue::filepath(d.path).into_value(&d.tag),
);
r.insert(
@ -389,7 +389,7 @@ impl From<FileInfo> for Value {
r.insert(
"path".to_string(),
UntaggedValue::path(f.path).into_value(&f.tag),
UntaggedValue::filepath(f.path).into_value(&f.tag),
);
r.insert(

View File

@ -27,7 +27,7 @@ impl WholeStreamCommand for Enter {
Signature::build("enter")
.required(
"location",
SyntaxShape::Path,
SyntaxShape::FilePath,
"the location to create a new shell from",
)
.named(

View File

@ -21,8 +21,11 @@ impl WholeStreamCommand for Exec {
fn signature(&self) -> Signature {
Signature::build("exec")
.required("command", SyntaxShape::Path, "the command to execute")
.rest(SyntaxShape::Pattern, "any additional arguments for command")
.required("command", SyntaxShape::FilePath, "the command to execute")
.rest(
SyntaxShape::GlobPattern,
"any additional arguments for command",
)
}
fn usage(&self) -> &str {

View File

@ -28,7 +28,7 @@ impl WholeStreamCommand for Ls {
Signature::build("ls")
.optional(
"path",
SyntaxShape::Pattern,
SyntaxShape::GlobPattern,
"a path to get the directory contents from",
)
.switch("all", "Show hidden files", Some('a'))

View File

@ -22,7 +22,10 @@ impl WholeStreamCommand for Mkdir {
fn signature(&self) -> Signature {
Signature::build("mkdir")
.rest(SyntaxShape::Path, "the name(s) of the path(s) to create")
.rest(
SyntaxShape::FilePath,
"the name(s) of the path(s) to create",
)
.switch("show-created-paths", "show the path(s) created.", Some('s'))
}

View File

@ -23,12 +23,12 @@ impl WholeStreamCommand for Mv {
Signature::build("mv")
.required(
"source",
SyntaxShape::Pattern,
SyntaxShape::GlobPattern,
"the location to move files/directories from",
)
.required(
"destination",
SyntaxShape::Path,
SyntaxShape::FilePath,
"the location to move files/directories to",
)
}

View File

@ -28,7 +28,7 @@ impl WholeStreamCommand for SubCommand {
fn signature(&self) -> Signature {
Signature::build("nu plugin").named(
"load",
SyntaxShape::Path,
SyntaxShape::FilePath,
"a path to load the plugins from",
Some('l'),
)

View File

@ -29,7 +29,7 @@ impl WholeStreamCommand for Open {
Signature::build(self.name())
.required(
"path",
SyntaxShape::Path,
SyntaxShape::FilePath,
"the file path to load values from",
)
.switch(

View File

@ -59,7 +59,7 @@ impl WholeStreamCommand for PathBasename {
Example {
description: "Replace basename of a path",
example: "echo 'C:\\Users\\joe\\test.txt' | path basename -r 'spam.png'",
result: Some(vec![Value::from(UntaggedValue::path(
result: Some(vec![Value::from(UntaggedValue::filepath(
"C:\\Users\\joe\\spam.png",
))]),
},
@ -77,7 +77,9 @@ impl WholeStreamCommand for PathBasename {
Example {
description: "Replace basename of a path",
example: "echo '/home/joe/test.txt' | path basename -r 'spam.png'",
result: Some(vec![Value::from(UntaggedValue::path("/home/joe/spam.png"))]),
result: Some(vec![Value::from(UntaggedValue::filepath(
"/home/joe/spam.png",
))]),
},
]
}
@ -85,7 +87,7 @@ impl WholeStreamCommand for PathBasename {
fn action(path: &Path, args: Arc<DefaultArguments>) -> UntaggedValue {
match args.replace {
Some(ref basename) => UntaggedValue::path(path.with_file_name(basename)),
Some(ref basename) => UntaggedValue::filepath(path.with_file_name(basename)),
None => UntaggedValue::string(match path.file_name() {
Some(filename) => filename.to_string_lossy(),
None => "".into(),

View File

@ -69,20 +69,20 @@ impl WholeStreamCommand for PathDirname {
Example {
description: "Get dirname of a path",
example: "echo 'C:\\Users\\joe\\code\\test.txt' | path dirname",
result: Some(vec![Value::from(UntaggedValue::path(
result: Some(vec![Value::from(UntaggedValue::filepath(
"C:\\Users\\joe\\code",
))]),
},
Example {
description: "Set how many levels up to skip",
example: "echo 'C:\\Users\\joe\\code\\test.txt' | path dirname -n 2",
result: Some(vec![Value::from(UntaggedValue::path("C:\\Users\\joe"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("C:\\Users\\joe"))]),
},
Example {
description: "Replace the part that would be returned with custom string",
example:
"echo 'C:\\Users\\joe\\code\\test.txt' | path dirname -n 2 -r C:\\Users\\viking",
result: Some(vec![Value::from(UntaggedValue::path(
result: Some(vec![Value::from(UntaggedValue::filepath(
"C:\\Users\\viking\\code\\test.txt",
))]),
},
@ -95,17 +95,17 @@ impl WholeStreamCommand for PathDirname {
Example {
description: "Get dirname of a path",
example: "echo '/home/joe/code/test.txt' | path dirname",
result: Some(vec![Value::from(UntaggedValue::path("/home/joe/code"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("/home/joe/code"))]),
},
Example {
description: "Set how many levels up to skip",
example: "echo '/home/joe/code/test.txt' | path dirname -n 2",
result: Some(vec![Value::from(UntaggedValue::path("/home/joe"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("/home/joe"))]),
},
Example {
description: "Replace the part that would be returned with custom string",
example: "echo '/home/joe/code/test.txt' | path dirname -n 2 -r /home/viking",
result: Some(vec![Value::from(UntaggedValue::path(
result: Some(vec![Value::from(UntaggedValue::filepath(
"/home/viking/code/test.txt",
))]),
},
@ -132,12 +132,12 @@ fn action(path: &Path, args: Arc<DefaultArguments>) -> UntaggedValue {
Some(ref newdir) => {
let remainder = path.strip_prefix(dirname).unwrap_or(dirname);
if !remainder.as_os_str().is_empty() {
UntaggedValue::path(Path::new(newdir).join(remainder))
UntaggedValue::filepath(Path::new(newdir).join(remainder))
} else {
UntaggedValue::path(Path::new(newdir))
UntaggedValue::filepath(Path::new(newdir))
}
}
None => UntaggedValue::path(dirname),
None => UntaggedValue::filepath(dirname),
}
}

View File

@ -65,7 +65,7 @@ fn action(path: &Path, _args: Arc<DefaultArguments>) -> UntaggedValue {
let ps = path.to_string_lossy();
let expanded = shellexpand::tilde(&ps);
let path: &Path = expanded.as_ref().as_ref();
UntaggedValue::path(dunce::canonicalize(path).unwrap_or_else(|_| PathBuf::from(path)))
UntaggedValue::filepath(dunce::canonicalize(path).unwrap_or_else(|_| PathBuf::from(path)))
}
#[cfg(test)]

View File

@ -63,12 +63,12 @@ impl WholeStreamCommand for PathExtension {
Example {
description: "Replace an extension with a custom string",
example: "echo 'test.txt' | path extension -r md",
result: Some(vec![Value::from(UntaggedValue::path("test.md"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("test.md"))]),
},
Example {
description: "To replace more complex extensions:",
example: "echo 'test.tar.gz' | path extension -r '' | path extension -r txt",
result: Some(vec![Value::from(UntaggedValue::path("test.txt"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("test.txt"))]),
},
]
}
@ -76,7 +76,7 @@ impl WholeStreamCommand for PathExtension {
fn action(path: &Path, args: Arc<DefaultArguments>) -> UntaggedValue {
match args.replace {
Some(ref extension) => UntaggedValue::path(path.with_extension(extension)),
Some(ref extension) => UntaggedValue::filepath(path.with_extension(extension)),
None => UntaggedValue::string(match path.extension() {
Some(extension) => extension.to_string_lossy(),
None => "".into(),

View File

@ -86,7 +86,7 @@ impl WholeStreamCommand for PathFilestem {
Example {
description: "Replace the filestem that would be returned",
example: "echo 'C:\\Users\\joe\\bacon_lettuce.egg.gz' | path filestem -p bacon_ -s .egg.gz -r spam",
result: Some(vec![Value::from(UntaggedValue::path("C:\\Users\\joe\\bacon_spam.egg.gz"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("C:\\Users\\joe\\bacon_spam.egg.gz"))]),
},
]
}
@ -107,7 +107,7 @@ impl WholeStreamCommand for PathFilestem {
Example {
description: "Replace the filestem that would be returned",
example: "echo '/home/joe/bacon_lettuce.egg.gz' | path filestem -p bacon_ -s .egg.gz -r spam",
result: Some(vec![Value::from(UntaggedValue::path("/home/joe/bacon_spam.egg.gz"))]),
result: Some(vec![Value::from(UntaggedValue::filepath("/home/joe/bacon_spam.egg.gz"))]),
},
]
}
@ -152,7 +152,7 @@ fn action(path: &Path, args: Arc<DefaultArguments>) -> UntaggedValue {
match args.replace {
Some(ref replace) => {
let new_name = prefix + replace + &suffix;
UntaggedValue::path(path.with_file_name(&new_name))
UntaggedValue::filepath(path.with_file_name(&new_name))
}
None => UntaggedValue::string(stem),
}

View File

@ -46,7 +46,7 @@ where
F: Fn(&Path, Arc<DefaultArguments>) -> UntaggedValue + Send + 'static,
{
let v = match &v.value {
UntaggedValue::Primitive(Primitive::Path(buf)) => action(buf, args).into_value(v.tag()),
UntaggedValue::Primitive(Primitive::FilePath(buf)) => action(buf, args).into_value(v.tag()),
UntaggedValue::Primitive(Primitive::String(s)) => {
action(s.as_ref(), args).into_value(v.tag())
}

View File

@ -38,7 +38,7 @@ impl WholeStreamCommand for Remove {
)
.switch("recursive", "delete subdirectories recursively", Some('r'))
.switch("force", "suppress error when no file", Some('f'))
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
.rest(SyntaxShape::GlobPattern, "the file path(s) to remove")
}
fn usage(&self) -> &str {

View File

@ -140,7 +140,11 @@ impl WholeStreamCommand for Save {
fn signature(&self) -> Signature {
Signature::build("save")
.optional("path", SyntaxShape::Path, "the path to save contents to")
.optional(
"path",
SyntaxShape::FilePath,
"the path to save contents to",
)
.switch(
"raw",
"treat values as-is rather than auto-converting based on file extension",

View File

@ -112,8 +112,8 @@ pub fn clone_tagged_value(v: &Value) -> Value {
UntaggedValue::Primitive(Primitive::Int(i)) => {
UntaggedValue::Primitive(Primitive::Int(i.clone()))
}
UntaggedValue::Primitive(Primitive::Path(x)) => {
UntaggedValue::Primitive(Primitive::Path(x.clone()))
UntaggedValue::Primitive(Primitive::FilePath(x)) => {
UntaggedValue::Primitive(Primitive::FilePath(x.clone()))
}
UntaggedValue::Primitive(Primitive::Filesize(b)) => {
UntaggedValue::Primitive(Primitive::Filesize(*b))
@ -136,7 +136,7 @@ fn to_string_tagged_value(v: &Value) -> Result<String, ShellError> {
| UntaggedValue::Primitive(Primitive::Filesize(_))
| UntaggedValue::Primitive(Primitive::Boolean(_))
| UntaggedValue::Primitive(Primitive::Decimal(_))
| UntaggedValue::Primitive(Primitive::Path(_))
| UntaggedValue::Primitive(Primitive::FilePath(_))
| UntaggedValue::Primitive(Primitive::Int(_)) => as_string(v),
UntaggedValue::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
UntaggedValue::Primitive(Primitive::Nothing) => Ok(String::new()),

View File

@ -96,7 +96,7 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
)?))
}
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::GlobPattern(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
path.iter()
@ -113,7 +113,7 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
})
.collect::<Result<Vec<serde_json::Value>, ShellError>>()?,
),
UntaggedValue::Primitive(Primitive::Path(s)) => {
UntaggedValue::Primitive(Primitive::FilePath(s)) => {
serde_json::Value::String(s.display().to_string())
}

View File

@ -58,9 +58,9 @@ fn helper(v: &Value) -> Result<toml::Value, ShellError> {
UntaggedValue::Primitive(Primitive::Nothing) => {
toml::Value::String("<Nothing>".to_string())
}
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::GlobPattern(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::Path(s)) => {
UntaggedValue::Primitive(Primitive::FilePath(s)) => {
toml::Value::String(s.display().to_string())
}
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => toml::Value::Array(

View File

@ -58,7 +58,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
)?))
}
UntaggedValue::Primitive(Primitive::Nothing) => serde_yaml::Value::Null,
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_yaml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::GlobPattern(s)) => serde_yaml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
let mut out = vec![];
@ -79,7 +79,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
serde_yaml::Value::Sequence(out)
}
UntaggedValue::Primitive(Primitive::Path(s)) => {
UntaggedValue::Primitive(Primitive::FilePath(s)) => {
serde_yaml::Value::String(s.display().to_string())
}

View File

@ -23,10 +23,10 @@ impl WholeStreamCommand for Touch {
Signature::build("touch")
.required(
"filename",
SyntaxShape::Path,
SyntaxShape::FilePath,
"the path of the file you want to create",
)
.rest(SyntaxShape::Path, "additional files to create")
.rest(SyntaxShape::FilePath, "additional files to create")
}
fn usage(&self) -> &str {
"creates one or more files"

View File

@ -60,7 +60,7 @@ macro_rules! entry_path {
($arg:expr, $path:expr, $tag:expr) => {
entry(
$arg.clone(),
UntaggedValue::Primitive(Primitive::Path($path)).into_value($tag.clone()),
UntaggedValue::Primitive(Primitive::FilePath($path)).into_value($tag.clone()),
false,
$tag,
)

View File

@ -425,7 +425,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
..
} => visit::<Tagged<bool>, _>(false.tagged(tag), name, fields, visitor),
Value {
value: UntaggedValue::Primitive(Primitive::Path(p)),
value: UntaggedValue::Primitive(Primitive::FilePath(p)),
..
} => visit::<Tagged<PathBuf>, _>(p.tagged(tag), name, fields, visitor),
Value {

View File

@ -29,7 +29,7 @@ pub(crate) async fn evaluate_baseline_expr(
"Invalid external word".spanned(tag.span),
ArgumentError::InvalidExternalWord,
)),
Expression::FilePath(path) => Ok(UntaggedValue::path(path.clone()).into_value(tag)),
Expression::FilePath(path) => Ok(UntaggedValue::filepath(path.clone()).into_value(tag)),
Expression::Synthetic(hir::Synthetic::String(s)) => {
Ok(UntaggedValue::string(s).into_untagged_value())
}
@ -213,7 +213,7 @@ fn evaluate_literal(literal: &hir::Literal, span: Span) -> Value {
},
hir::Literal::Size(int, unit) => unit.compute(&int).into_value(span),
hir::Literal::String(string) => UntaggedValue::string(string).into_value(span),
hir::Literal::GlobPattern(pattern) => UntaggedValue::pattern(pattern).into_value(span),
hir::Literal::GlobPattern(pattern) => UntaggedValue::glob_pattern(pattern).into_value(span),
hir::Literal::Bare(bare) => UntaggedValue::string(bare.clone()).into_value(span),
hir::Literal::Operator(_) => unimplemented!("Not sure what to do with operator yet"),
}

View File

@ -23,30 +23,33 @@ pub fn nu(env: &IndexMap<String, String>, tag: impl Into<Tag>) -> Result<Value,
let path = std::env::var_os("PATH");
if let Some(paths) = path {
for path in std::env::split_paths(&paths) {
table.push(UntaggedValue::path(path).into_value(&tag));
table.push(UntaggedValue::filepath(path).into_value(&tag));
}
}
nu_dict.insert_value("path", UntaggedValue::table(&table).into_value(&tag));
let path = std::env::current_dir()?;
nu_dict.insert_value("cwd", UntaggedValue::path(path).into_value(&tag));
nu_dict.insert_value("cwd", UntaggedValue::filepath(path).into_value(&tag));
if let Some(home) = crate::shell::filesystem_shell::homedir_if_possible() {
nu_dict.insert_value("home-dir", UntaggedValue::path(home).into_value(&tag));
nu_dict.insert_value("home-dir", UntaggedValue::filepath(home).into_value(&tag));
}
let temp = std::env::temp_dir();
nu_dict.insert_value("temp-dir", UntaggedValue::path(temp).into_value(&tag));
nu_dict.insert_value("temp-dir", UntaggedValue::filepath(temp).into_value(&tag));
let config = nu_data::config::default_path()?;
nu_dict.insert_value("config-path", UntaggedValue::path(config).into_value(&tag));
nu_dict.insert_value(
"config-path",
UntaggedValue::filepath(config).into_value(&tag),
);
#[cfg(feature = "rustyline-support")]
{
let keybinding_path = crate::keybinding::keybinding_path()?;
nu_dict.insert_value(
"keybinding-path",
UntaggedValue::path(keybinding_path).into_value(&tag),
UntaggedValue::filepath(keybinding_path).into_value(&tag),
);
}
@ -54,7 +57,7 @@ pub fn nu(env: &IndexMap<String, String>, tag: impl Into<Tag>) -> Result<Value,
let history = crate::commands::history::history_path(&config);
nu_dict.insert_value(
"history-path",
UntaggedValue::path(history).into_value(&tag),
UntaggedValue::filepath(history).into_value(&tag),
);
Ok(nu_dict.into_value())

View File

@ -979,7 +979,7 @@ pub(crate) fn dir_entry_dict(
)
})?;
dict.insert_untagged("name", UntaggedValue::path(name));
dict.insert_untagged("name", UntaggedValue::filepath(name));
if let Some(md) = metadata {
dict.insert_untagged("type", get_file_type(md));

View File

@ -296,7 +296,7 @@ fn get_shape_of_expr(expr: &SpannedExpression) -> Option<SyntaxShape> {
Expression::Boolean(_) => Some(SyntaxShape::String),
Expression::Path(_) => Some(SyntaxShape::ColumnPath),
Expression::FilePath(_) => Some(SyntaxShape::Path),
Expression::FilePath(_) => Some(SyntaxShape::FilePath),
Expression::Block(_) => Some(SyntaxShape::Block),
Expression::ExternalCommand(_) => Some(SyntaxShape::String),
Expression::Table(_, _) => Some(SyntaxShape::Table),

View File

@ -149,10 +149,10 @@ pub fn coerce_compare_primitive(
(Date(left), Date(right)) => CompareValues::Date(*left, *right),
(Date(left), Duration(right)) => CompareValues::DateDuration(*left, right.clone()),
(Boolean(left), Boolean(right)) => CompareValues::Booleans(*left, *right),
(Path(left), String(right)) => {
(FilePath(left), String(right)) => {
CompareValues::String(left.as_path().display().to_string(), right.clone())
}
(String(left), Path(right)) => {
(String(left), FilePath(right)) => {
CompareValues::String(left.clone(), right.as_path().display().to_string())
}
_ => return Err((left.type_name(), right.type_name())),

View File

@ -29,11 +29,11 @@ pub enum InlineShape {
String(String),
Line(String),
ColumnPath(ColumnPath),
Pattern(String),
GlobPattern(String),
Boolean(bool),
Date(DateTime<FixedOffset>),
Duration(BigInt),
Path(PathBuf),
FilePath(PathBuf),
Binary(usize),
Row(Row),
@ -72,11 +72,11 @@ impl InlineShape {
Primitive::Filesize(bytesize) => InlineShape::Bytesize(*bytesize),
Primitive::String(string) => InlineShape::String(string.clone()),
Primitive::ColumnPath(path) => InlineShape::ColumnPath(path.clone()),
Primitive::Pattern(pattern) => InlineShape::Pattern(pattern.clone()),
Primitive::GlobPattern(pattern) => InlineShape::GlobPattern(pattern.clone()),
Primitive::Boolean(boolean) => InlineShape::Boolean(*boolean),
Primitive::Date(date) => InlineShape::Date(*date),
Primitive::Duration(duration) => InlineShape::Duration(duration.clone()),
Primitive::Path(path) => InlineShape::Path(path.clone()),
Primitive::FilePath(path) => InlineShape::FilePath(path.clone()),
Primitive::Binary(b) => InlineShape::Binary(b.len()),
Primitive::BeginningOfStream => InlineShape::BeginningOfStream,
Primitive::EndOfStream => InlineShape::EndOfStream,
@ -208,7 +208,7 @@ impl PrettyDebug for FormatInlineShape {
InlineShape::ColumnPath(path) => {
b::intersperse(path.iter().map(|member| member.pretty()), b::keyword("."))
}
InlineShape::Pattern(pattern) => b::primitive(pattern),
InlineShape::GlobPattern(pattern) => b::primitive(pattern),
InlineShape::Boolean(boolean) => b::primitive(
match (boolean, column) {
(true, None) => "Yes",
@ -225,7 +225,7 @@ impl PrettyDebug for FormatInlineShape {
&Primitive::Duration(duration.clone()),
None,
)),
InlineShape::Path(path) => b::primitive(path.display()),
InlineShape::FilePath(path) => b::primitive(path.display()),
InlineShape::Binary(length) => b::opaque(format!("<binary: {} bytes>", length)),
InlineShape::Row(row) => b::delimit(
"[",

View File

@ -81,9 +81,9 @@ fn helper(v: &Value) -> Result<toml::Value, ShellError> {
UntaggedValue::Primitive(Primitive::Nothing) => {
toml::Value::String("<Nothing>".to_string())
}
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::GlobPattern(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::Path(s)) => {
UntaggedValue::Primitive(Primitive::FilePath(s)) => {
toml::Value::String(s.display().to_string())
}
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => toml::Value::Array(

View File

@ -91,12 +91,12 @@ pub fn string_to_lookup_value(str_prim: &str) -> String {
"primitive_string" => "Primitive::String".to_string(),
"primitive_line" => "Primitive::Line".to_string(),
"primitive_columnpath" => "Primitive::ColumnPath".to_string(),
"primitive_pattern" => "Primitive::Pattern".to_string(),
"primitive_pattern" => "Primitive::GlobPattern".to_string(),
"primitive_boolean" => "Primitive::Boolean".to_string(),
"primitive_date" => "Primitive::Date".to_string(),
"primitive_duration" => "Primitive::Duration".to_string(),
"primitive_range" => "Primitive::Range".to_string(),
"primitive_path" => "Primitive::Path".to_string(),
"primitive_path" => "Primitive::FilePath".to_string(),
"primitive_binary" => "Primitive::Binary".to_string(),
"separator_color" => "separator_color".to_string(),
"header_align" => "header_align".to_string(),
@ -269,8 +269,8 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap<String, Style>) -> Te
None => TextStyle::basic_left(),
}
}
"Pattern" => {
let style = color_hm.get("Primitive::Pattern");
"GlobPattern" => {
let style = color_hm.get("Primitive::GlobPattern");
match style {
Some(s) => TextStyle::with_style(Alignment::Left, *s),
None => TextStyle::basic_left(),
@ -304,8 +304,8 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap<String, Style>) -> Te
None => TextStyle::basic_left(),
}
}
"Path" => {
let style = color_hm.get("Primitive::Path");
"FilePath" => {
let style = color_hm.get("Primitive::FilePath");
match style {
Some(s) => TextStyle::with_style(Alignment::Left, *s),
None => TextStyle::basic_left(),

View File

@ -36,7 +36,7 @@ impl ExtractType for std::path::PathBuf {
match &value {
Value {
value: UntaggedValue::Primitive(Primitive::Path(p)),
value: UntaggedValue::Primitive(Primitive::FilePath(p)),
..
} => Ok(p.clone()),
other => Err(ShellError::type_error("Path", other.spanned_type_name())),

View File

@ -816,11 +816,11 @@ fn parse_arg(
)
}
}
SyntaxShape::Pattern => {
SyntaxShape::GlobPattern => {
let trimmed = trim_quotes(&lite_arg.item);
let expanded = expand_path(&trimmed).to_string();
(
SpannedExpression::new(Expression::pattern(expanded), lite_arg.span),
SpannedExpression::new(Expression::glob_pattern(expanded), lite_arg.span),
None,
)
}
@ -828,7 +828,7 @@ fn parse_arg(
SyntaxShape::Range => parse_range(&lite_arg, scope),
SyntaxShape::Operator => parse_operator(&lite_arg),
SyntaxShape::Unit => parse_unit(&lite_arg),
SyntaxShape::Path => {
SyntaxShape::FilePath => {
let trimmed = trim_quotes(&lite_arg.item);
let expanded = expand_path(&trimmed).to_string();
let path = Path::new(&expanded);
@ -2077,11 +2077,11 @@ fn parse_signature(
let shape = match parts[1] {
"int" => SyntaxShape::Int,
"string" => SyntaxShape::String,
"path" => SyntaxShape::Path,
"path" => SyntaxShape::FilePath,
"table" => SyntaxShape::Table,
"unit" => SyntaxShape::Unit,
"number" => SyntaxShape::Number,
"pattern" => SyntaxShape::Pattern,
"pattern" => SyntaxShape::GlobPattern,
"range" => SyntaxShape::Range,
"block" => SyntaxShape::Block,
"any" => SyntaxShape::Any,
@ -2105,11 +2105,11 @@ fn parse_signature(
let shape = match parts[1] {
"int" => SyntaxShape::Int,
"string" => SyntaxShape::String,
"path" => SyntaxShape::Path,
"path" => SyntaxShape::FilePath,
"table" => SyntaxShape::Table,
"unit" => SyntaxShape::Unit,
"number" => SyntaxShape::Number,
"pattern" => SyntaxShape::Pattern,
"pattern" => SyntaxShape::GlobPattern,
"range" => SyntaxShape::Range,
"block" => SyntaxShape::Block,
"any" => SyntaxShape::Any,

View File

@ -1092,7 +1092,7 @@ impl Expression {
}))
}
pub fn pattern(p: String) -> Expression {
pub fn glob_pattern(p: String) -> Expression {
Expression::Literal(Literal::GlobPattern(p))
}

View File

@ -19,9 +19,9 @@ pub enum SyntaxShape {
/// Only an integer value is allowed
Int,
/// A filepath is allowed
Path,
FilePath,
/// A glob pattern is allowed, eg `foo*`
Pattern,
GlobPattern,
/// A block is allowed, eg `{start this thing}`
Block,
/// A table is allowed, eg `[first second]`
@ -48,8 +48,8 @@ impl PrettyDebug for SyntaxShape {
SyntaxShape::Number => "number",
SyntaxShape::Range => "range",
SyntaxShape::Int => "integer",
SyntaxShape::Path => "file path",
SyntaxShape::Pattern => "pattern",
SyntaxShape::FilePath => "file path",
SyntaxShape::GlobPattern => "pattern",
SyntaxShape::Block => "block",
SyntaxShape::Table => "table",
SyntaxShape::Unit => "unit",

View File

@ -43,7 +43,7 @@ pub enum Type {
/// A path through a table
ColumnPath,
/// A glob pattern (like foo*)
Pattern,
GlobPattern,
/// A boolean value
Boolean,
/// A date value (in UTC)
@ -51,7 +51,7 @@ pub enum Type {
/// A data duration value
Duration,
/// A filepath value
Path,
FilePath,
/// A binary (non-text) buffer value
Binary,
@ -141,11 +141,11 @@ impl Type {
Primitive::Filesize(_) => Type::Filesize,
Primitive::String(_) => Type::String,
Primitive::ColumnPath(_) => Type::ColumnPath,
Primitive::Pattern(_) => Type::Pattern,
Primitive::GlobPattern(_) => Type::GlobPattern,
Primitive::Boolean(_) => Type::Boolean,
Primitive::Date(_) => Type::Date,
Primitive::Duration(_) => Type::Duration,
Primitive::Path(_) => Type::Path,
Primitive::FilePath(_) => Type::FilePath,
Primitive::Binary(_) => Type::Binary,
Primitive::BeginningOfStream => Type::BeginningOfStream,
Primitive::EndOfStream => Type::EndOfStream,
@ -223,11 +223,11 @@ impl PrettyDebug for Type {
Type::String => ty("string"),
Type::Line => ty("line"),
Type::ColumnPath => ty("column-path"),
Type::Pattern => ty("pattern"),
Type::GlobPattern => ty("pattern"),
Type::Boolean => ty("boolean"),
Type::Date => ty("date"),
Type::Duration => ty("duration"),
Type::Path => ty("path"),
Type::FilePath => ty("path"),
Type::Binary => ty("binary"),
Type::Error => b::error("error"),
Type::BeginningOfStream => b::keyword("beginning-of-stream"),

View File

@ -175,13 +175,13 @@ impl UntaggedValue {
}
/// Helper for creating glob pattern values
pub fn pattern(s: impl Into<String>) -> UntaggedValue {
pub fn glob_pattern(s: impl Into<String>) -> UntaggedValue {
UntaggedValue::Primitive(Primitive::String(s.into()))
}
/// Helper for creating filepath values
pub fn path(s: impl Into<PathBuf>) -> UntaggedValue {
UntaggedValue::Primitive(Primitive::Path(s.into()))
pub fn filepath(s: impl Into<PathBuf>) -> UntaggedValue {
UntaggedValue::Primitive(Primitive::FilePath(s.into()))
}
/// Helper for creating filesize values
@ -312,7 +312,7 @@ impl Value {
pub fn as_string(&self) -> Result<String, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::String(string)) => Ok(string.clone()),
UntaggedValue::Primitive(Primitive::Path(path)) => {
UntaggedValue::Primitive(Primitive::FilePath(path)) => {
Ok(path.to_string_lossy().to_string())
}
_ => Err(ShellError::type_error("string", self.spanned_type_name())),
@ -327,7 +327,7 @@ impl Value {
UntaggedValue::Primitive(Primitive::Decimal(x)) => format!("{}", x),
UntaggedValue::Primitive(Primitive::Int(x)) => format!("{}", x),
UntaggedValue::Primitive(Primitive::Filesize(x)) => format!("{}", x),
UntaggedValue::Primitive(Primitive::Path(x)) => format!("{}", x.display()),
UntaggedValue::Primitive(Primitive::FilePath(x)) => format!("{}", x.display()),
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
let joined: String = path
.iter()
@ -364,7 +364,7 @@ impl Value {
/// View the Value as a path, if possible
pub fn as_path(&self) -> Result<PathBuf, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::Path(path)) => Ok(path.clone()),
UntaggedValue::Primitive(Primitive::FilePath(path)) => Ok(path.clone()),
UntaggedValue::Primitive(Primitive::String(path_str)) => Ok(PathBuf::from(&path_str)),
_ => Err(ShellError::type_error("Path", self.spanned_type_name())),
}
@ -623,13 +623,13 @@ impl StringExt for String {
fn to_pattern_value(&self, the_tag: Tag) -> Value {
Value {
value: UntaggedValue::Primitive(Primitive::Pattern(self.to_string())),
value: UntaggedValue::Primitive(Primitive::GlobPattern(self.to_string())),
tag: the_tag,
}
}
fn to_pattern_untagged_value(&self) -> UntaggedValue {
UntaggedValue::pattern(self)
UntaggedValue::glob_pattern(self)
}
}
@ -682,13 +682,13 @@ impl StrExt for &str {
fn to_pattern_value(&self, the_tag: Tag) -> Value {
Value {
value: UntaggedValue::Primitive(Primitive::Pattern(self.to_string())),
value: UntaggedValue::Primitive(Primitive::GlobPattern(self.to_string())),
tag: the_tag,
}
}
fn to_pattern_untagged_value(&self) -> UntaggedValue {
UntaggedValue::pattern(*self)
UntaggedValue::glob_pattern(*self)
}
}
@ -830,7 +830,7 @@ impl PathBufExt for PathBuf {
fn to_value(&self, the_tag: Tag) -> Value {
let pb = self.clone();
Value {
value: UntaggedValue::Primitive(Primitive::Path(pb)),
value: UntaggedValue::Primitive(Primitive::FilePath(pb)),
tag: the_tag,
}
}
@ -842,7 +842,7 @@ impl PathBufExt for PathBuf {
.len();
let pb = self.clone();
Value {
value: UntaggedValue::Primitive(Primitive::Path(pb)),
value: UntaggedValue::Primitive(Primitive::FilePath(pb)),
tag: Tag {
anchor: None,
span: Span::new(0, end),
@ -852,7 +852,7 @@ impl PathBufExt for PathBuf {
fn to_untagged_value(&self) -> UntaggedValue {
let pb = self.clone();
UntaggedValue::path(pb)
UntaggedValue::filepath(pb)
}
}
@ -988,7 +988,7 @@ mod tests {
let a_pattern = r"[a-zA-Z0-9 ]";
assert_eq!(
a_pattern.to_pattern_untagged_value(),
UntaggedValue::pattern(a_pattern)
UntaggedValue::glob_pattern(a_pattern)
);
}

View File

@ -36,11 +36,11 @@ impl PrettyType for Primitive {
Primitive::Filesize(_) => ty("filesize"),
Primitive::String(_) => ty("string"),
Primitive::ColumnPath(_) => ty("column-path"),
Primitive::Pattern(_) => ty("pattern"),
Primitive::GlobPattern(_) => ty("pattern"),
Primitive::Boolean(_) => ty("boolean"),
Primitive::Date(_) => ty("date"),
Primitive::Duration(_) => ty("duration"),
Primitive::Path(_) => ty("path"),
Primitive::FilePath(_) => ty("path"),
Primitive::Binary(_) => ty("binary"),
Primitive::BeginningOfStream => b::keyword("beginning-of-stream"),
Primitive::EndOfStream => b::keyword("end-of-stream"),
@ -73,14 +73,14 @@ impl PrettyDebug for Primitive {
Primitive::Filesize(bytes) => primitive_doc(bytes, "filesize"),
Primitive::String(string) => prim(string),
Primitive::ColumnPath(path) => path.pretty(),
Primitive::Pattern(pattern) => primitive_doc(pattern, "pattern"),
Primitive::GlobPattern(pattern) => primitive_doc(pattern, "pattern"),
Primitive::Boolean(boolean) => match boolean {
true => b::primitive("$yes"),
false => b::primitive("$no"),
},
Primitive::Date(date) => primitive_doc(date, "date"),
Primitive::Duration(duration) => primitive_doc(duration, "nanoseconds"),
Primitive::Path(path) => primitive_doc(path, "path"),
Primitive::FilePath(path) => primitive_doc(path, "path"),
Primitive::Binary(_) => b::opaque("binary"),
Primitive::BeginningOfStream => b::keyword("beginning-of-stream"),
Primitive::EndOfStream => b::keyword("end-of-stream"),

View File

@ -37,7 +37,7 @@ pub enum Primitive {
/// A path to travel to reach a value in a table
ColumnPath(ColumnPath),
/// A glob pattern, eg foo*
Pattern(String),
GlobPattern(String),
/// A boolean value
Boolean(bool),
/// A date value
@ -48,7 +48,7 @@ pub enum Primitive {
/// A range of values
Range(Box<Range>),
/// A file path
Path(PathBuf),
FilePath(PathBuf),
/// A vector of raw binary data
#[serde(with = "serde_bytes")]
Binary(Vec<u8>),
@ -234,11 +234,11 @@ impl ShellTypeName for Primitive {
Primitive::Filesize(_) => "filesize(in bytes)",
Primitive::String(_) => "string",
Primitive::ColumnPath(_) => "column path",
Primitive::Pattern(_) => "pattern",
Primitive::GlobPattern(_) => "pattern",
Primitive::Boolean(_) => "boolean",
Primitive::Date(_) => "date",
Primitive::Duration(_) => "duration",
Primitive::Path(_) => "file path",
Primitive::FilePath(_) => "file path",
Primitive::Binary(_) => "binary",
Primitive::BeginningOfStream => "marker<beginning of stream>",
Primitive::EndOfStream => "marker<end of stream>",
@ -252,7 +252,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
Primitive::Nothing => String::new(),
Primitive::BeginningOfStream => String::new(),
Primitive::EndOfStream => String::new(),
Primitive::Path(p) => format!("{}", p.display()),
Primitive::FilePath(p) => format!("{}", p.display()),
Primitive::Filesize(num_bytes) => {
let byte = byte_unit::Byte::from_bytes(*num_bytes as u128);
@ -289,7 +289,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
},
format_primitive(&range.to.0.item, None)
),
Primitive::Pattern(s) => s.to_string(),
Primitive::GlobPattern(s) => s.to_string(),
Primitive::String(s) => s.to_owned(),
Primitive::ColumnPath(p) => {
let mut members = p.iter();

View File

@ -680,7 +680,7 @@ pub fn as_string(value: &Value) -> Result<String, ShellError> {
UntaggedValue::Primitive(Primitive::Decimal(x)) => Ok(format!("{}", x)),
UntaggedValue::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)),
UntaggedValue::Primitive(Primitive::Filesize(x)) => Ok(format!("{}", x)),
UntaggedValue::Primitive(Primitive::Path(x)) => Ok(format!("{}", x.display())),
UntaggedValue::Primitive(Primitive::FilePath(x)) => Ok(format!("{}", x.display())),
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => Ok(path
.iter()
.map(|member| match &member.unspanned {

View File

@ -378,7 +378,7 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
)?))
}
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::GlobPattern(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
path.iter()
@ -395,7 +395,7 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
})
.collect::<Result<Vec<serde_json::Value>, ShellError>>()?,
),
UntaggedValue::Primitive(Primitive::Path(s)) => {
UntaggedValue::Primitive(Primitive::FilePath(s)) => {
serde_json::Value::String(s.display().to_string())
}

View File

@ -56,8 +56,8 @@ pub fn value_to_bson_value(v: &Value) -> Result<Bson, ShellError> {
})
.collect::<Result<Vec<Bson>, ShellError>>()?,
),
UntaggedValue::Primitive(Primitive::Pattern(p)) => Bson::String(p.clone()),
UntaggedValue::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()),
UntaggedValue::Primitive(Primitive::GlobPattern(p)) => Bson::String(p.clone()),
UntaggedValue::Primitive(Primitive::FilePath(s)) => Bson::String(s.display().to_string()),
UntaggedValue::Table(l) => Bson::Array(
l.iter()
.map(|x| value_to_bson_value(x))

View File

@ -45,12 +45,12 @@ fn nu_value_to_sqlite_string(v: Value) -> String {
Primitive::Duration(i) => format!("{}", i),
Primitive::Decimal(f) => format!("{}", f),
Primitive::Filesize(u) => format!("{}", u),
Primitive::Pattern(s) => format!("'{}'", s.replace("'", "''")),
Primitive::GlobPattern(s) => format!("'{}'", s.replace("'", "''")),
Primitive::String(s) => format!("'{}'", s.replace("'", "''")),
Primitive::Boolean(true) => "1".into(),
Primitive::Boolean(_) => "0".into(),
Primitive::Date(d) => format!("'{}'", d),
Primitive::Path(p) => format!("'{}'", p.display().to_string().replace("'", "''")),
Primitive::FilePath(p) => format!("'{}'", p.display().to_string().replace("'", "''")),
Primitive::Binary(u) => format!("x'{}'", encode(u)),
Primitive::BeginningOfStream
| Primitive::EndOfStream