mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
trim lines in command
This commit is contained in:
parent
637e4f6e6d
commit
25a776c36b
2 changed files with 7 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
use nu_engine::eval_expression;
|
use nu_engine::eval_expression;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
use nu_protocol::engine::{Command, EvaluationContext};
|
||||||
use nu_protocol::{Signature, SyntaxShape, Value};
|
use nu_protocol::{ShellError, Signature, SyntaxShape, Value};
|
||||||
|
|
||||||
pub struct BuildString;
|
pub struct BuildString;
|
||||||
|
|
||||||
|
@ -24,13 +24,12 @@ impl Command for BuildString {
|
||||||
call: &Call,
|
call: &Call,
|
||||||
_input: Value,
|
_input: Value,
|
||||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
let mut output = vec![];
|
let output = call
|
||||||
|
.positional
|
||||||
|
.iter()
|
||||||
|
.map(|expr| eval_expression(context, expr).map(|val| val.into_string()))
|
||||||
|
.collect::<Result<Vec<String>, ShellError>>()?;
|
||||||
|
|
||||||
for expr in &call.positional {
|
|
||||||
let val = eval_expression(context, expr)?;
|
|
||||||
|
|
||||||
output.push(val.into_string());
|
|
||||||
}
|
|
||||||
Ok(Value::String {
|
Ok(Value::String {
|
||||||
val: output.join(""),
|
val: output.join(""),
|
||||||
span: call.head,
|
span: call.head,
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl Command for Lines {
|
||||||
.filter_map(|s| {
|
.filter_map(|s| {
|
||||||
if !s.is_empty() {
|
if !s.is_empty() {
|
||||||
Some(Value::String {
|
Some(Value::String {
|
||||||
val: s.into(),
|
val: s.trim().into(),
|
||||||
span,
|
span,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue