mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:06:03 +02:00
Do some str collect cleanup (#312)
This commit is contained in:
@ -212,7 +212,7 @@ pub fn action(
|
||||
},
|
||||
|
||||
Value::Filesize { val: _, .. } => Value::String {
|
||||
val: input.clone().into_string(),
|
||||
val: input.clone().into_string(", "),
|
||||
span,
|
||||
},
|
||||
Value::Nothing { .. } => Value::String {
|
||||
|
@ -52,7 +52,7 @@ impl Command for BuildString {
|
||||
let output = call
|
||||
.positional
|
||||
.iter()
|
||||
.map(|expr| eval_expression(engine_state, stack, expr).map(|val| val.into_string()))
|
||||
.map(|expr| eval_expression(engine_state, stack, expr).map(|val| val.into_string(", ")))
|
||||
.collect::<Result<Vec<String>, ShellError>>()?;
|
||||
|
||||
Ok(Value::String {
|
||||
|
@ -34,31 +34,25 @@ impl Command for StrCollect {
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let separator: Option<String> = call.opt(engine_state, stack, 0)?;
|
||||
|
||||
// Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable
|
||||
// which feels funny
|
||||
#[allow(clippy::needless_collect)]
|
||||
let strings: Vec<Result<String, ShellError>> =
|
||||
input.into_iter().map(|value| value.as_string()).collect();
|
||||
let strings: Result<Vec<_>, _> = strings.into_iter().collect::<Result<_, _>>();
|
||||
let strings: Vec<String> = input
|
||||
.into_iter()
|
||||
.map(|value| value.debug_string("\n"))
|
||||
.collect();
|
||||
|
||||
match strings {
|
||||
Ok(strings) => {
|
||||
let output = if let Some(separator) = separator {
|
||||
strings.join(&separator)
|
||||
} else {
|
||||
strings.join("")
|
||||
};
|
||||
let output = if let Some(separator) = separator {
|
||||
strings.join(&separator)
|
||||
} else {
|
||||
strings.join("")
|
||||
};
|
||||
|
||||
Ok(Value::String {
|
||||
val: output,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data())
|
||||
}
|
||||
_ => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
"non-string input".into(),
|
||||
call.head,
|
||||
)),
|
||||
Ok(Value::String {
|
||||
val: output,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -111,7 +111,7 @@ impl ExternalCommand {
|
||||
}
|
||||
}
|
||||
x => {
|
||||
if stdin_write.write(x.into_string().as_bytes()).is_err() {
|
||||
if stdin_write.write(x.into_string(", ").as_bytes()).is_err() {
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ prints out the list properly."#
|
||||
let mut items = vec![];
|
||||
|
||||
for (i, (c, v)) in cols.into_iter().zip(vals.into_iter()).enumerate() {
|
||||
items.push((i, c, v.into_string()))
|
||||
items.push((i, c, v.into_string(", ")))
|
||||
}
|
||||
|
||||
Ok(create_grid_output2(
|
||||
@ -187,7 +187,7 @@ fn convert_to_list2(iter: impl IntoIterator<Item = Value>) -> Option<Vec<(usize,
|
||||
let mut row = vec![row_num.to_string()];
|
||||
|
||||
if headers.is_empty() {
|
||||
row.push(item.into_string())
|
||||
row.push(item.into_string(", "))
|
||||
} else {
|
||||
for header in headers.iter().skip(1) {
|
||||
let result = match item {
|
||||
@ -201,7 +201,7 @@ fn convert_to_list2(iter: impl IntoIterator<Item = Value>) -> Option<Vec<(usize,
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(value) => row.push(value.into_string()),
|
||||
Ok(value) => row.push(value.into_string(", ")),
|
||||
Err(_) => row.push(String::new()),
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl Command for Table {
|
||||
style: nu_table::TextStyle::default_field(),
|
||||
},
|
||||
StyledString {
|
||||
contents: v.into_string(),
|
||||
contents: v.into_string(", "),
|
||||
style: nu_table::TextStyle::default(),
|
||||
},
|
||||
])
|
||||
@ -123,7 +123,7 @@ fn convert_to_table(
|
||||
let mut row = vec![row_num.to_string()];
|
||||
|
||||
if headers.is_empty() {
|
||||
row.push(item.into_string())
|
||||
row.push(item.into_string(", "))
|
||||
} else {
|
||||
for header in headers.iter().skip(1) {
|
||||
let result = match item {
|
||||
@ -137,7 +137,7 @@ fn convert_to_table(
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(value) => row.push(value.into_string()),
|
||||
Ok(value) => row.push(value.into_string(", ")),
|
||||
Err(_) => row.push(String::new()),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user