mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
to-[csv/tsv] fixes.
This commit is contained in:
parent
2dcbf78385
commit
ba8383ae2f
4 changed files with 17 additions and 5 deletions
|
@ -37,6 +37,9 @@ pub fn value_to_csv_value(v: &Value) -> Value {
|
|||
Value::Primitive(Primitive::String(s)) => Value::Primitive(Primitive::String(s.clone())),
|
||||
Value::Primitive(Primitive::Nothing) => Value::Primitive(Primitive::Nothing),
|
||||
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
|
||||
Value::Primitive(Primitive::Decimal(f)) => Value::Primitive(Primitive::Decimal(f.clone())),
|
||||
Value::Primitive(Primitive::Int(i)) => Value::Primitive(Primitive::Int(i.clone())),
|
||||
Value::Primitive(Primitive::Path(x)) => Value::Primitive(Primitive::Path(x.clone())),
|
||||
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
|
||||
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
|
||||
Value::Row(o) => Value::Row(o.clone()),
|
||||
|
@ -51,8 +54,11 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
|
|||
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
||||
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
||||
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
||||
Value::Table(_) => return Ok(String::from("[list list]")),
|
||||
Value::Row(_) => return Ok(String::from("[object]")),
|
||||
Value::Primitive(Primitive::Decimal(_)) => Ok(v.as_string()?),
|
||||
Value::Primitive(Primitive::Int(_)) => Ok(v.as_string()?),
|
||||
Value::Primitive(Primitive::Path(_)) => Ok(v.as_string()?),
|
||||
Value::Table(_) => return Ok(String::from("[Table]")),
|
||||
Value::Row(_) => return Ok(String::from("[Row]")),
|
||||
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
||||
_ => return Err(ShellError::string("Unexpected value")),
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ pub fn value_to_tsv_value(v: &Value) -> Value {
|
|||
Value::Primitive(Primitive::String(s)) => Value::Primitive(Primitive::String(s.clone())),
|
||||
Value::Primitive(Primitive::Nothing) => Value::Primitive(Primitive::Nothing),
|
||||
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
|
||||
Value::Primitive(Primitive::Decimal(f)) => Value::Primitive(Primitive::Decimal(f.clone())),
|
||||
Value::Primitive(Primitive::Int(i)) => Value::Primitive(Primitive::Int(i.clone())),
|
||||
Value::Primitive(Primitive::Path(x)) => Value::Primitive(Primitive::Path(x.clone())),
|
||||
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
|
||||
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
|
||||
Value::Row(o) => Value::Row(o.clone()),
|
||||
|
@ -51,10 +54,13 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
|
|||
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
|
||||
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
|
||||
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
|
||||
Value::Primitive(Primitive::Decimal(_)) => Ok(v.as_string()?),
|
||||
Value::Primitive(Primitive::Int(_)) => Ok(v.as_string()?),
|
||||
Value::Primitive(Primitive::Path(_)) => Ok(v.as_string()?),
|
||||
Value::Table(_) => return Ok(String::from("[table]")),
|
||||
Value::Row(_) => return Ok(String::from("[row]")),
|
||||
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
|
||||
_ => Err(ShellError::string("Unexpected value")),
|
||||
_ => return Err(ShellError::string("Unexpected value")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -435,7 +435,7 @@ pub fn view_contents_interactive(
|
|||
let cursor = cursor();
|
||||
let _ = cursor.show();
|
||||
|
||||
let screen = RawScreen::disable_raw_mode();
|
||||
let _screen = RawScreen::disable_raw_mode();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ fn save_can_write_out_csv() {
|
|||
);
|
||||
|
||||
let actual = h::file_contents(expected_file);
|
||||
assert!(actual.contains("[list list],A shell for the GitHub era,2018,ISC,nu,0.2.0"));
|
||||
assert!(actual.contains("[Table],A shell for the GitHub era,2018,ISC,nu,0.2.0"));
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue