mirror of
https://github.com/nushell/nushell.git
synced 2025-04-02 20:27:11 +02:00
Remove the line primitive (#2887)
This commit is contained in:
parent
eb3c2c9e76
commit
ac9909112f
@ -133,29 +133,6 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
|
|||||||
} => {
|
} => {
|
||||||
out!("{}", s);
|
out!("{}", s);
|
||||||
}
|
}
|
||||||
Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(ref s)),
|
|
||||||
tag: Tag { anchor, span },
|
|
||||||
} if anchor.is_some() => {
|
|
||||||
if let Some(text) = text {
|
|
||||||
let mut stream = VecDeque::new();
|
|
||||||
stream.push_back(
|
|
||||||
UntaggedValue::string(s).into_value(Tag { anchor, span }),
|
|
||||||
);
|
|
||||||
let command_args =
|
|
||||||
create_default_command_args(&context).with_input(stream);
|
|
||||||
let result = text.run(command_args).await?;
|
|
||||||
result.collect::<Vec<_>>().await;
|
|
||||||
} else {
|
|
||||||
out!("{}\n", s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(s)),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
out!("{}\n", s);
|
|
||||||
}
|
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::Path(s)),
|
value: UntaggedValue::Primitive(Primitive::Path(s)),
|
||||||
..
|
..
|
||||||
|
@ -221,8 +221,7 @@ fn spawn(
|
|||||||
for value in block_on_stream(input) {
|
for value in block_on_stream(input) {
|
||||||
match &value.value {
|
match &value.value {
|
||||||
UntaggedValue::Primitive(Primitive::Nothing) => continue,
|
UntaggedValue::Primitive(Primitive::Nothing) => continue,
|
||||||
UntaggedValue::Primitive(Primitive::String(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::Line(s)) => {
|
|
||||||
if stdin_write.write(s.as_bytes()).is_err() {
|
if stdin_write.write(s.as_bytes()).is_err() {
|
||||||
// Other side has closed, so exit
|
// Other side has closed, so exit
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -164,8 +164,7 @@ fn action(
|
|||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let base64_config_enum: base64::Config = if &base64_config.character_set == "standard" {
|
let base64_config_enum: base64::Config = if &base64_config.character_set == "standard" {
|
||||||
base64::STANDARD
|
base64::STANDARD
|
||||||
} else if &base64_config.character_set == "standard-no-padding" {
|
} else if &base64_config.character_set == "standard-no-padding" {
|
||||||
|
@ -63,10 +63,6 @@ async fn lines(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::String(st)),
|
value: UntaggedValue::Primitive(Primitive::String(st)),
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(st)),
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
let mut leftover_string = leftover_string.lock();
|
let mut leftover_string = leftover_string.lock();
|
||||||
|
|
||||||
@ -84,7 +80,9 @@ async fn lines(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
let success_lines: Vec<_> = lines
|
let success_lines: Vec<_> = lines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| ReturnSuccess::value(UntaggedValue::line(x).into_untagged_value()))
|
.map(|x| {
|
||||||
|
ReturnSuccess::value(UntaggedValue::string(x).into_untagged_value())
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
futures::stream::iter(success_lines)
|
futures::stream::iter(success_lines)
|
||||||
|
@ -47,8 +47,7 @@ where
|
|||||||
{
|
{
|
||||||
let v = match &v.value {
|
let v = match &v.value {
|
||||||
UntaggedValue::Primitive(Primitive::Path(buf)) => action(buf, args).into_value(v.tag()),
|
UntaggedValue::Primitive(Primitive::Path(buf)) => action(buf, args).into_value(v.tag()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::Line(s)) => {
|
|
||||||
action(s.as_ref(), args).into_value(v.tag())
|
action(s.as_ref(), args).into_value(v.tag())
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
|
@ -72,8 +72,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let mut capitalized = String::new();
|
let mut capitalized = String::new();
|
||||||
|
|
||||||
for (idx, character) in s.chars().enumerate() {
|
for (idx, character) in s.chars().enumerate() {
|
||||||
|
@ -61,8 +61,7 @@ where
|
|||||||
F: Fn(&str) -> String + Send + Sync + 'static,
|
F: Fn(&str) -> String + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
Ok(UntaggedValue::string(case_operation(s)).into_value(tag))
|
Ok(UntaggedValue::string(case_operation(s)).into_value(tag))
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
|
@ -96,8 +96,7 @@ fn action(
|
|||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let contains = if insensitive {
|
let contains = if insensitive {
|
||||||
s.to_lowercase().find(&pattern.to_lowercase()).is_some()
|
s.to_lowercase().find(&pattern.to_lowercase()).is_some()
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,8 +72,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
Ok(UntaggedValue::string(s.to_ascii_lowercase()).into_value(tag))
|
Ok(UntaggedValue::string(s.to_ascii_lowercase()).into_value(tag))
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
|
@ -75,8 +75,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let ends_with = s.ends_with(pattern);
|
let ends_with = s.ends_with(pattern);
|
||||||
Ok(UntaggedValue::boolean(ends_with).into_value(tag))
|
Ok(UntaggedValue::boolean(ends_with).into_value(tag))
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,7 @@ fn action(
|
|||||||
all: bool,
|
all: bool,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let find = &options.0;
|
let find = &options.0;
|
||||||
let replacement = &options.1;
|
let replacement = &options.1;
|
||||||
|
|
||||||
|
@ -137,8 +137,7 @@ fn action(
|
|||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let r = process_range(&input, &range)?;
|
let r = process_range(&input, &range)?;
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let start_index = r.0 as usize;
|
let start_index = r.0 as usize;
|
||||||
let end_index = r.1 as usize;
|
let end_index = r.1 as usize;
|
||||||
|
|
||||||
@ -169,15 +168,13 @@ fn action(
|
|||||||
|
|
||||||
fn process_range(input: &Value, range: &Value) -> Result<IndexOfOptionalBounds, ShellError> {
|
fn process_range(input: &Value, range: &Value) -> Result<IndexOfOptionalBounds, ShellError> {
|
||||||
let input_len = match &input.value {
|
let input_len = match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => s.len(),
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => s.len(),
|
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
let min_index_str = String::from("0");
|
let min_index_str = String::from("0");
|
||||||
let max_index_str = input_len.to_string();
|
let max_index_str = input_len.to_string();
|
||||||
let r = match &range.value {
|
let r = match &range.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let indexes: Vec<&str> = s.split(',').collect();
|
let indexes: Vec<&str> = s.split(',').collect();
|
||||||
|
|
||||||
let start_index = indexes.get(0).unwrap_or(&&min_index_str[..]).to_string();
|
let start_index = indexes.get(0).unwrap_or(&&min_index_str[..]).to_string();
|
||||||
|
@ -111,8 +111,7 @@ fn action(
|
|||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
if length < s.len() {
|
if length < s.len() {
|
||||||
Ok(UntaggedValue::string(&s[0..length]).into_value(tag))
|
Ok(UntaggedValue::string(&s[0..length]).into_value(tag))
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,8 +111,7 @@ fn action(
|
|||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
if length < s.len() {
|
if length < s.len() {
|
||||||
Ok(UntaggedValue::string(&s[0..length]).into_value(tag))
|
Ok(UntaggedValue::string(&s[0..length]).into_value(tag))
|
||||||
} else {
|
} else {
|
||||||
|
@ -75,8 +75,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let starts_with = s.starts_with(pattern);
|
let starts_with = s.starts_with(pattern);
|
||||||
Ok(UntaggedValue::boolean(starts_with).into_value(tag))
|
Ok(UntaggedValue::boolean(starts_with).into_value(tag))
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,7 @@ fn action(input: &Value, options: &Substring, tag: impl Into<Tag>) -> Result<Val
|
|||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
|
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let len: isize = s.len().try_into().map_err(|_| {
|
let len: isize = s.len().try_into().map_err(|_| {
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"could not perform substring",
|
"could not perform substring",
|
||||||
|
@ -109,8 +109,7 @@ fn action(
|
|||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let out = match options {
|
let out = match options {
|
||||||
Some(dt) => match DateTime::parse_from_str(s, &dt.0) {
|
Some(dt) => match DateTime::parse_from_str(s, &dt.0) {
|
||||||
Ok(d) => UntaggedValue::date(d),
|
Ok(d) => UntaggedValue::date(d),
|
||||||
|
@ -75,8 +75,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let other = s.trim();
|
let other = s.trim();
|
||||||
let out = match BigDecimal::from_str(other) {
|
let out = match BigDecimal::from_str(other) {
|
||||||
Ok(v) => UntaggedValue::decimal(v),
|
Ok(v) => UntaggedValue::decimal(v),
|
||||||
|
@ -97,8 +97,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>, radix: u32) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>, radix: u32) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
let trimmed = s.trim();
|
let trimmed = s.trim();
|
||||||
|
|
||||||
let out = match trimmed {
|
let out = match trimmed {
|
||||||
|
@ -80,8 +80,7 @@ where
|
|||||||
{
|
{
|
||||||
let tag = tag.into();
|
let tag = tag.into();
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
Ok(UntaggedValue::string(trim_operation(s, char_)).into_value(tag))
|
Ok(UntaggedValue::string(trim_operation(s, char_)).into_value(tag))
|
||||||
}
|
}
|
||||||
other => match mode {
|
other => match mode {
|
||||||
|
@ -72,8 +72,7 @@ async fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
|
|
||||||
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
fn action(input: &Value, tag: impl Into<Tag>) -> Result<Value, ShellError> {
|
||||||
match &input.value {
|
match &input.value {
|
||||||
UntaggedValue::Primitive(Primitive::Line(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => {
|
||||||
| UntaggedValue::Primitive(Primitive::String(s)) => {
|
|
||||||
Ok(UntaggedValue::string(s.to_ascii_uppercase()).into_value(tag))
|
Ok(UntaggedValue::string(s.to_ascii_uppercase()).into_value(tag))
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
|
@ -133,7 +133,6 @@ pub fn clone_tagged_value(v: &Value) -> Value {
|
|||||||
fn to_string_tagged_value(v: &Value) -> Result<String, ShellError> {
|
fn to_string_tagged_value(v: &Value) -> Result<String, ShellError> {
|
||||||
match &v.value {
|
match &v.value {
|
||||||
UntaggedValue::Primitive(Primitive::String(_))
|
UntaggedValue::Primitive(Primitive::String(_))
|
||||||
| UntaggedValue::Primitive(Primitive::Line(_))
|
|
||||||
| UntaggedValue::Primitive(Primitive::Filesize(_))
|
| UntaggedValue::Primitive(Primitive::Filesize(_))
|
||||||
| UntaggedValue::Primitive(Primitive::Boolean(_))
|
| UntaggedValue::Primitive(Primitive::Boolean(_))
|
||||||
| UntaggedValue::Primitive(Primitive::Decimal(_))
|
| UntaggedValue::Primitive(Primitive::Decimal(_))
|
||||||
|
@ -98,7 +98,6 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
|
|||||||
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
|
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
|
||||||
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => serde_json::Value::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
|
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
|
||||||
path.iter()
|
path.iter()
|
||||||
.map(|x| match &x.unspanned {
|
.map(|x| match &x.unspanned {
|
||||||
|
@ -60,7 +60,6 @@ fn helper(v: &Value) -> Result<toml::Value, ShellError> {
|
|||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => toml::Value::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::Path(s)) => {
|
UntaggedValue::Primitive(Primitive::Path(s)) => {
|
||||||
toml::Value::String(s.display().to_string())
|
toml::Value::String(s.display().to_string())
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,6 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
|
|||||||
UntaggedValue::Primitive(Primitive::Nothing) => serde_yaml::Value::Null,
|
UntaggedValue::Primitive(Primitive::Nothing) => serde_yaml::Value::Null,
|
||||||
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_yaml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_yaml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => serde_yaml::Value::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
|
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => {
|
||||||
let mut out = vec![];
|
let mut out = vec![];
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ where
|
|||||||
{
|
{
|
||||||
let a = |url| UntaggedValue::string(action(url));
|
let a = |url| UntaggedValue::string(action(url));
|
||||||
let v = match &v.value {
|
let v = match &v.value {
|
||||||
UntaggedValue::Primitive(Primitive::String(s))
|
UntaggedValue::Primitive(Primitive::String(s)) => match Url::parse(s) {
|
||||||
| UntaggedValue::Primitive(Primitive::Line(s)) => match Url::parse(s) {
|
|
||||||
Ok(url) => a(&url).into_value(v.tag()),
|
Ok(url) => a(&url).into_value(v.tag()),
|
||||||
Err(_) => UntaggedValue::string("").into_value(v.tag()),
|
Err(_) => UntaggedValue::string("").into_value(v.tag()),
|
||||||
},
|
},
|
||||||
|
@ -63,18 +63,6 @@ fn string_contains(
|
|||||||
UntaggedValue::Primitive(Primitive::String(l)),
|
UntaggedValue::Primitive(Primitive::String(l)),
|
||||||
UntaggedValue::Primitive(Primitive::String(r)),
|
UntaggedValue::Primitive(Primitive::String(r)),
|
||||||
) => Ok(l.contains(r)),
|
) => Ok(l.contains(r)),
|
||||||
(
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(l)),
|
|
||||||
UntaggedValue::Primitive(Primitive::String(r)),
|
|
||||||
) => Ok(l.contains(r)),
|
|
||||||
(
|
|
||||||
UntaggedValue::Primitive(Primitive::String(l)),
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(r)),
|
|
||||||
) => Ok(l.contains(r)),
|
|
||||||
(
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(l)),
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(r)),
|
|
||||||
) => Ok(l.contains(r)),
|
|
||||||
_ => Err((left.type_name(), right.type_name())),
|
_ => Err((left.type_name(), right.type_name())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ fn lines_proper_buffering() {
|
|||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_eq!(actual.out, "[8194,4]");
|
assert_eq!(actual.out, "[8193,3]");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -146,9 +146,6 @@ pub fn coerce_compare_primitive(
|
|||||||
}
|
}
|
||||||
(Nothing, Nothing) => CompareValues::Booleans(true, true),
|
(Nothing, Nothing) => CompareValues::Booleans(true, true),
|
||||||
(String(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
|
(String(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
|
||||||
(Line(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
|
|
||||||
(String(left), Line(right)) => CompareValues::String(left.clone(), right.clone()),
|
|
||||||
(Line(left), Line(right)) => CompareValues::String(left.clone(), right.clone()),
|
|
||||||
(Date(left), Date(right)) => CompareValues::Date(*left, *right),
|
(Date(left), Date(right)) => CompareValues::Date(*left, *right),
|
||||||
(Date(left), Duration(right)) => CompareValues::DateDuration(*left, right.clone()),
|
(Date(left), Duration(right)) => CompareValues::DateDuration(*left, right.clone()),
|
||||||
(Boolean(left), Boolean(right)) => CompareValues::Booleans(*left, *right),
|
(Boolean(left), Boolean(right)) => CompareValues::Booleans(*left, *right),
|
||||||
|
@ -71,7 +71,6 @@ impl InlineShape {
|
|||||||
Primitive::Decimal(decimal) => InlineShape::Decimal(decimal.clone()),
|
Primitive::Decimal(decimal) => InlineShape::Decimal(decimal.clone()),
|
||||||
Primitive::Filesize(bytesize) => InlineShape::Bytesize(*bytesize),
|
Primitive::Filesize(bytesize) => InlineShape::Bytesize(*bytesize),
|
||||||
Primitive::String(string) => InlineShape::String(string.clone()),
|
Primitive::String(string) => InlineShape::String(string.clone()),
|
||||||
Primitive::Line(string) => InlineShape::Line(string.clone()),
|
|
||||||
Primitive::ColumnPath(path) => InlineShape::ColumnPath(path.clone()),
|
Primitive::ColumnPath(path) => InlineShape::ColumnPath(path.clone()),
|
||||||
Primitive::Pattern(pattern) => InlineShape::Pattern(pattern.clone()),
|
Primitive::Pattern(pattern) => InlineShape::Pattern(pattern.clone()),
|
||||||
Primitive::Boolean(boolean) => InlineShape::Boolean(*boolean),
|
Primitive::Boolean(boolean) => InlineShape::Boolean(*boolean),
|
||||||
|
@ -83,7 +83,6 @@ fn helper(v: &Value) -> Result<toml::Value, ShellError> {
|
|||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::Pattern(s)) => toml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => toml::Value::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::Path(s)) => {
|
UntaggedValue::Primitive(Primitive::Path(s)) => {
|
||||||
toml::Value::String(s.display().to_string())
|
toml::Value::String(s.display().to_string())
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,6 @@ impl ExtractType for String {
|
|||||||
value: UntaggedValue::Primitive(Primitive::String(string)),
|
value: UntaggedValue::Primitive(Primitive::String(string)),
|
||||||
..
|
..
|
||||||
} => Ok(string.clone()),
|
} => Ok(string.clone()),
|
||||||
Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(string)),
|
|
||||||
..
|
|
||||||
} => Ok(string.clone()),
|
|
||||||
other => Err(ShellError::type_error("String", other.spanned_type_name())),
|
other => Err(ShellError::type_error("String", other.spanned_type_name())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,6 @@ impl Type {
|
|||||||
Primitive::Decimal(_) => Type::Decimal,
|
Primitive::Decimal(_) => Type::Decimal,
|
||||||
Primitive::Filesize(_) => Type::Filesize,
|
Primitive::Filesize(_) => Type::Filesize,
|
||||||
Primitive::String(_) => Type::String,
|
Primitive::String(_) => Type::String,
|
||||||
Primitive::Line(_) => Type::Line,
|
|
||||||
Primitive::ColumnPath(_) => Type::ColumnPath,
|
Primitive::ColumnPath(_) => Type::ColumnPath,
|
||||||
Primitive::Pattern(_) => Type::Pattern,
|
Primitive::Pattern(_) => Type::Pattern,
|
||||||
Primitive::Boolean(_) => Type::Boolean,
|
Primitive::Boolean(_) => Type::Boolean,
|
||||||
|
@ -162,11 +162,6 @@ impl UntaggedValue {
|
|||||||
UntaggedValue::Primitive(Primitive::String(s.into()))
|
UntaggedValue::Primitive(Primitive::String(s.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for creating line values
|
|
||||||
pub fn line(s: impl Into<String>) -> UntaggedValue {
|
|
||||||
UntaggedValue::Primitive(Primitive::Line(s.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper for creating column-path values
|
/// Helper for creating column-path values
|
||||||
pub fn column_path(s: &str, span: Span) -> UntaggedValue {
|
pub fn column_path(s: &str, span: Span) -> UntaggedValue {
|
||||||
let s = s.to_string().spanned(span);
|
let s = s.to_string().spanned(span);
|
||||||
@ -317,7 +312,6 @@ impl Value {
|
|||||||
pub fn as_string(&self) -> Result<String, ShellError> {
|
pub fn as_string(&self) -> Result<String, ShellError> {
|
||||||
match &self.value {
|
match &self.value {
|
||||||
UntaggedValue::Primitive(Primitive::String(string)) => Ok(string.clone()),
|
UntaggedValue::Primitive(Primitive::String(string)) => Ok(string.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(line)) => Ok(line.clone() + "\n"),
|
|
||||||
UntaggedValue::Primitive(Primitive::Path(path)) => {
|
UntaggedValue::Primitive(Primitive::Path(path)) => {
|
||||||
Ok(path.to_string_lossy().to_string())
|
Ok(path.to_string_lossy().to_string())
|
||||||
}
|
}
|
||||||
@ -584,8 +578,6 @@ pub trait StringExt {
|
|||||||
fn to_string_untagged_value(&self) -> UntaggedValue;
|
fn to_string_untagged_value(&self) -> UntaggedValue;
|
||||||
fn to_string_value(&self, tag: Tag) -> Value;
|
fn to_string_value(&self, tag: Tag) -> Value;
|
||||||
fn to_string_value_create_tag(&self) -> Value;
|
fn to_string_value_create_tag(&self) -> Value;
|
||||||
fn to_line_value(&self, tag: Tag) -> Value;
|
|
||||||
fn to_line_untagged_value(&self) -> UntaggedValue;
|
|
||||||
fn to_column_path_value(&self, tag: Tag) -> Value;
|
fn to_column_path_value(&self, tag: Tag) -> Value;
|
||||||
fn to_column_path_untagged_value(&self, span: Span) -> UntaggedValue;
|
fn to_column_path_untagged_value(&self, span: Span) -> UntaggedValue;
|
||||||
fn to_pattern_value(&self, tag: Tag) -> Value;
|
fn to_pattern_value(&self, tag: Tag) -> Value;
|
||||||
@ -615,17 +607,6 @@ impl StringExt for String {
|
|||||||
UntaggedValue::string(self)
|
UntaggedValue::string(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_line_value(&self, the_tag: Tag) -> Value {
|
|
||||||
Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(self.to_string())),
|
|
||||||
tag: the_tag,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_line_untagged_value(&self) -> UntaggedValue {
|
|
||||||
UntaggedValue::line(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_column_path_value(&self, the_tag: Tag) -> Value {
|
fn to_column_path_value(&self, the_tag: Tag) -> Value {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::build(
|
value: UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::build(
|
||||||
@ -656,8 +637,6 @@ pub trait StrExt {
|
|||||||
fn to_str_untagged_value(&self) -> UntaggedValue;
|
fn to_str_untagged_value(&self) -> UntaggedValue;
|
||||||
fn to_str_value(&self, tag: Tag) -> Value;
|
fn to_str_value(&self, tag: Tag) -> Value;
|
||||||
fn to_str_value_create_tag(&self) -> Value;
|
fn to_str_value_create_tag(&self) -> Value;
|
||||||
fn to_line_value(&self, tag: Tag) -> Value;
|
|
||||||
fn to_line_untagged_value(&self) -> UntaggedValue;
|
|
||||||
fn to_column_path_value(&self, tag: Tag) -> Value;
|
fn to_column_path_value(&self, tag: Tag) -> Value;
|
||||||
fn to_column_path_untagged_value(&self, span: Span) -> UntaggedValue;
|
fn to_column_path_untagged_value(&self, span: Span) -> UntaggedValue;
|
||||||
fn to_pattern_value(&self, tag: Tag) -> Value;
|
fn to_pattern_value(&self, tag: Tag) -> Value;
|
||||||
@ -687,17 +666,6 @@ impl StrExt for &str {
|
|||||||
UntaggedValue::string(*self)
|
UntaggedValue::string(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_line_value(&self, the_tag: Tag) -> Value {
|
|
||||||
Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(self.to_string())),
|
|
||||||
tag: the_tag,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_line_untagged_value(&self) -> UntaggedValue {
|
|
||||||
UntaggedValue::line(*self)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_column_path_value(&self, the_tag: Tag) -> Value {
|
fn to_column_path_value(&self, the_tag: Tag) -> Value {
|
||||||
Value {
|
Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::build(
|
value: UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::build(
|
||||||
@ -1015,12 +983,6 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_string_to_line_untagged_value() {
|
|
||||||
let a_line = r"this is some line\n";
|
|
||||||
assert_eq!(a_line.to_line_untagged_value(), UntaggedValue::line(a_line));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_string_to_pattern_untagged_value() {
|
fn test_string_to_pattern_untagged_value() {
|
||||||
let a_pattern = r"[a-zA-Z0-9 ]";
|
let a_pattern = r"[a-zA-Z0-9 ]";
|
||||||
|
@ -35,7 +35,6 @@ impl PrettyType for Primitive {
|
|||||||
Primitive::Decimal(_) => ty("decimal"),
|
Primitive::Decimal(_) => ty("decimal"),
|
||||||
Primitive::Filesize(_) => ty("filesize"),
|
Primitive::Filesize(_) => ty("filesize"),
|
||||||
Primitive::String(_) => ty("string"),
|
Primitive::String(_) => ty("string"),
|
||||||
Primitive::Line(_) => ty("line"),
|
|
||||||
Primitive::ColumnPath(_) => ty("column-path"),
|
Primitive::ColumnPath(_) => ty("column-path"),
|
||||||
Primitive::Pattern(_) => ty("pattern"),
|
Primitive::Pattern(_) => ty("pattern"),
|
||||||
Primitive::Boolean(_) => ty("boolean"),
|
Primitive::Boolean(_) => ty("boolean"),
|
||||||
@ -73,7 +72,6 @@ impl PrettyDebug for Primitive {
|
|||||||
}
|
}
|
||||||
Primitive::Filesize(bytes) => primitive_doc(bytes, "filesize"),
|
Primitive::Filesize(bytes) => primitive_doc(bytes, "filesize"),
|
||||||
Primitive::String(string) => prim(string),
|
Primitive::String(string) => prim(string),
|
||||||
Primitive::Line(string) => prim(string),
|
|
||||||
Primitive::ColumnPath(path) => path.pretty(),
|
Primitive::ColumnPath(path) => path.pretty(),
|
||||||
Primitive::Pattern(pattern) => primitive_doc(pattern, "pattern"),
|
Primitive::Pattern(pattern) => primitive_doc(pattern, "pattern"),
|
||||||
Primitive::Boolean(boolean) => match boolean {
|
Primitive::Boolean(boolean) => match boolean {
|
||||||
|
@ -34,8 +34,6 @@ pub enum Primitive {
|
|||||||
Filesize(u64),
|
Filesize(u64),
|
||||||
/// A string value
|
/// A string value
|
||||||
String(String),
|
String(String),
|
||||||
/// A string value with an implied carriage return (or cr/lf) ending
|
|
||||||
Line(String),
|
|
||||||
/// A path to travel to reach a value in a table
|
/// A path to travel to reach a value in a table
|
||||||
ColumnPath(ColumnPath),
|
ColumnPath(ColumnPath),
|
||||||
/// A glob pattern, eg foo*
|
/// A glob pattern, eg foo*
|
||||||
@ -235,7 +233,6 @@ impl ShellTypeName for Primitive {
|
|||||||
Primitive::Decimal(_) => "decimal",
|
Primitive::Decimal(_) => "decimal",
|
||||||
Primitive::Filesize(_) => "filesize(in bytes)",
|
Primitive::Filesize(_) => "filesize(in bytes)",
|
||||||
Primitive::String(_) => "string",
|
Primitive::String(_) => "string",
|
||||||
Primitive::Line(_) => "line",
|
|
||||||
Primitive::ColumnPath(_) => "column path",
|
Primitive::ColumnPath(_) => "column path",
|
||||||
Primitive::Pattern(_) => "pattern",
|
Primitive::Pattern(_) => "pattern",
|
||||||
Primitive::Boolean(_) => "boolean",
|
Primitive::Boolean(_) => "boolean",
|
||||||
@ -294,7 +291,6 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
|||||||
),
|
),
|
||||||
Primitive::Pattern(s) => s.to_string(),
|
Primitive::Pattern(s) => s.to_string(),
|
||||||
Primitive::String(s) => s.to_owned(),
|
Primitive::String(s) => s.to_owned(),
|
||||||
Primitive::Line(s) => s.to_owned(),
|
|
||||||
Primitive::ColumnPath(p) => {
|
Primitive::ColumnPath(p) => {
|
||||||
let mut members = p.iter();
|
let mut members = p.iter();
|
||||||
let mut f = String::new();
|
let mut f = String::new();
|
||||||
|
@ -60,13 +60,6 @@ impl InputStream {
|
|||||||
value_tag = value_t;
|
value_tag = value_t;
|
||||||
bytes.extend_from_slice(&s.into_bytes());
|
bytes.extend_from_slice(&s.into_bytes());
|
||||||
}
|
}
|
||||||
Some(Value {
|
|
||||||
value: UntaggedValue::Primitive(Primitive::Line(s)),
|
|
||||||
tag: value_t,
|
|
||||||
}) => {
|
|
||||||
value_tag = value_t;
|
|
||||||
bytes.extend_from_slice(&s.into_bytes());
|
|
||||||
}
|
|
||||||
Some(Value {
|
Some(Value {
|
||||||
value: UntaggedValue::Primitive(Primitive::Binary(b)),
|
value: UntaggedValue::Primitive(Primitive::Binary(b)),
|
||||||
tag: value_t,
|
tag: value_t,
|
||||||
|
@ -380,7 +380,6 @@ pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
|
|||||||
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
|
UntaggedValue::Primitive(Primitive::Nothing) => serde_json::Value::Null,
|
||||||
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::Pattern(s)) => serde_json::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => serde_json::Value::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
|
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => serde_json::Value::Array(
|
||||||
path.iter()
|
path.iter()
|
||||||
.map(|x| match &x.unspanned {
|
.map(|x| match &x.unspanned {
|
||||||
|
@ -46,7 +46,6 @@ pub fn value_to_bson_value(v: &Value) -> Result<Bson, ShellError> {
|
|||||||
}
|
}
|
||||||
UntaggedValue::Primitive(Primitive::Nothing) => Bson::Null,
|
UntaggedValue::Primitive(Primitive::Nothing) => Bson::Null,
|
||||||
UntaggedValue::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
|
UntaggedValue::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
|
||||||
UntaggedValue::Primitive(Primitive::Line(s)) => Bson::String(s.clone()),
|
|
||||||
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => Bson::Array(
|
UntaggedValue::Primitive(Primitive::ColumnPath(path)) => Bson::Array(
|
||||||
path.iter()
|
path.iter()
|
||||||
.map(|x| match &x.unspanned {
|
.map(|x| match &x.unspanned {
|
||||||
|
@ -47,7 +47,6 @@ fn nu_value_to_sqlite_string(v: Value) -> String {
|
|||||||
Primitive::Filesize(u) => format!("{}", u),
|
Primitive::Filesize(u) => format!("{}", u),
|
||||||
Primitive::Pattern(s) => format!("'{}'", s.replace("'", "''")),
|
Primitive::Pattern(s) => format!("'{}'", s.replace("'", "''")),
|
||||||
Primitive::String(s) => format!("'{}'", s.replace("'", "''")),
|
Primitive::String(s) => format!("'{}'", s.replace("'", "''")),
|
||||||
Primitive::Line(s) => format!("'{}'", s.replace("'", "''")),
|
|
||||||
Primitive::Boolean(true) => "1".into(),
|
Primitive::Boolean(true) => "1".into(),
|
||||||
Primitive::Boolean(_) => "0".into(),
|
Primitive::Boolean(_) => "0".into(),
|
||||||
Primitive::Date(d) => format!("'{}'", d),
|
Primitive::Date(d) => format!("'{}'", d),
|
||||||
|
Loading…
Reference in New Issue
Block a user