mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 02:27:50 +02:00
Add string stream and binary stream, add text decoding (#570)
* WIP * Add binary/string streams and text decoding * Make string collection fallible * Oops, forgot pretty hex * Oops, forgot pretty hex * clippy
This commit is contained in:
@ -52,7 +52,7 @@ pub fn from_delimited_data(
|
||||
name: Span,
|
||||
config: &Config,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let concat_string = input.collect_string("", config);
|
||||
let concat_string = input.collect_string("", config)?;
|
||||
|
||||
Ok(
|
||||
from_delimited_string_to_value(concat_string, noheaders, sep, name)
|
||||
|
@ -183,7 +183,7 @@ fn from_eml(
|
||||
head: Span,
|
||||
config: &Config,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let value = input.collect_string("", config);
|
||||
let value = input.collect_string("", config)?;
|
||||
|
||||
let body_preview = preview_body
|
||||
.map(|b| b.item as usize)
|
||||
|
@ -93,7 +93,7 @@ END:VCALENDAR' | from ics",
|
||||
}
|
||||
|
||||
fn from_ics(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let input_string = input.collect_string("", config);
|
||||
let input_string = input.collect_string("", config)?;
|
||||
let input_bytes = input_string.as_bytes();
|
||||
let buf_reader = BufReader::new(input_bytes);
|
||||
let parser = ical::IcalParser::new(buf_reader);
|
||||
|
@ -88,7 +88,7 @@ pub fn from_ini_string_to_value(s: String, span: Span) -> Result<Value, ShellErr
|
||||
}
|
||||
|
||||
fn from_ini(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let concat_string = input.collect_string("", config);
|
||||
let concat_string = input.collect_string("", config)?;
|
||||
|
||||
match from_ini_string_to_value(concat_string, head) {
|
||||
Ok(x) => Ok(x.into_pipeline_data()),
|
||||
|
@ -76,7 +76,7 @@ impl Command for FromJson {
|
||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||
let span = call.head;
|
||||
let config = stack.get_config().unwrap_or_default();
|
||||
let mut string_input = input.collect_string("", &config);
|
||||
let mut string_input = input.collect_string("", &config)?;
|
||||
string_input.push('\n');
|
||||
|
||||
// TODO: turn this into a structured underline of the nu_json error
|
||||
|
@ -275,7 +275,7 @@ fn from_ssv(
|
||||
let minimum_spaces: Option<Spanned<usize>> =
|
||||
call.get_flag(engine_state, stack, "minimum-spaces")?;
|
||||
|
||||
let concat_string = input.collect_string("", &config);
|
||||
let concat_string = input.collect_string("", &config)?;
|
||||
let split_at = match minimum_spaces {
|
||||
Some(number) => number.item,
|
||||
None => DEFAULT_MINIMUM_SPACES,
|
||||
|
@ -74,7 +74,7 @@ b = [1, 2]' | from toml",
|
||||
) -> Result<nu_protocol::PipelineData, ShellError> {
|
||||
let span = call.head;
|
||||
let config = stack.get_config().unwrap_or_default();
|
||||
let mut string_input = input.collect_string("", &config);
|
||||
let mut string_input = input.collect_string("", &config)?;
|
||||
string_input.push('\n');
|
||||
Ok(convert_string_to_value(string_input, span)?.into_pipeline_data())
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl Command for FromUrl {
|
||||
}
|
||||
|
||||
fn from_url(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let concat_string = input.collect_string("", config);
|
||||
let concat_string = input.collect_string("", config)?;
|
||||
|
||||
let result = serde_urlencoded::from_str::<Vec<(String, String)>>(&concat_string);
|
||||
|
||||
|
@ -124,7 +124,7 @@ END:VCARD' | from vcf",
|
||||
}
|
||||
|
||||
fn from_vcf(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let input_string = input.collect_string("", config);
|
||||
let input_string = input.collect_string("", config)?;
|
||||
let input_bytes = input_string.as_bytes();
|
||||
let cursor = std::io::Cursor::new(input_bytes);
|
||||
let parser = ical::VcardParser::new(cursor);
|
||||
|
@ -179,7 +179,7 @@ pub fn from_xml_string_to_value(s: String, span: Span) -> Result<Value, roxmltre
|
||||
}
|
||||
|
||||
fn from_xml(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let concat_string = input.collect_string("", config);
|
||||
let concat_string = input.collect_string("", config)?;
|
||||
|
||||
match from_xml_string_to_value(concat_string, head) {
|
||||
Ok(x) => Ok(x.into_pipeline_data()),
|
||||
|
@ -206,7 +206,7 @@ pub fn from_yaml_string_to_value(s: String, span: Span) -> Result<Value, ShellEr
|
||||
}
|
||||
|
||||
fn from_yaml(input: PipelineData, head: Span, config: &Config) -> Result<PipelineData, ShellError> {
|
||||
let concat_string = input.collect_string("", config);
|
||||
let concat_string = input.collect_string("", config)?;
|
||||
|
||||
match from_yaml_string_to_value(concat_string, head) {
|
||||
Ok(x) => Ok(x.into_pipeline_data()),
|
||||
|
@ -444,7 +444,7 @@ fn html_value(value: Value, config: &Config) -> String {
|
||||
let mut output_string = String::new();
|
||||
match value {
|
||||
Value::Binary { val, .. } => {
|
||||
let output = pretty_hex::pretty_hex(&val);
|
||||
let output = nu_pretty_hex::pretty_hex(&val);
|
||||
output_string.push_str("<pre>");
|
||||
output_string.push_str(&output);
|
||||
output_string.push_str("</pre>");
|
||||
|
Reference in New Issue
Block a user