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
48 changed files with 146 additions and 131 deletions

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())),