forked from extern/nushell
Make echo more flexible with data types
This commit is contained in:
parent
e75fdc2865
commit
a3679f0f4e
@ -35,37 +35,34 @@ fn run(
|
|||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
_raw_args: &RawCommandArgs,
|
_raw_args: &RawCommandArgs,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let name = call_info.name_tag.clone();
|
let mut output = vec![];
|
||||||
|
|
||||||
let mut output = String::new();
|
|
||||||
|
|
||||||
let mut first = true;
|
|
||||||
|
|
||||||
if let Some(ref positional) = call_info.args.positional {
|
if let Some(ref positional) = call_info.args.positional {
|
||||||
for i in positional {
|
for i in positional {
|
||||||
match i.as_string() {
|
match i.as_string() {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
if !first {
|
output.push(Ok(ReturnSuccess::Value(
|
||||||
output.push_str(" ");
|
Value::string(s).tagged(i.tag.clone()),
|
||||||
} else {
|
)));
|
||||||
first = false;
|
}
|
||||||
|
_ => match i {
|
||||||
|
Tagged {
|
||||||
|
item: Value::Table(table),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
for item in table {
|
||||||
|
output.push(Ok(ReturnSuccess::Value(item.clone())));
|
||||||
}
|
}
|
||||||
|
|
||||||
output.push_str(&s);
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(ShellError::type_error(
|
output.push(Ok(ReturnSuccess::Value(i.clone())));
|
||||||
"a string-compatible value",
|
|
||||||
i.tagged_type_name(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = VecDeque::from(vec![Ok(ReturnSuccess::Value(
|
let stream = VecDeque::from(output);
|
||||||
Value::string(output).tagged(name),
|
|
||||||
))]);
|
|
||||||
|
|
||||||
Ok(stream.to_output_stream())
|
Ok(stream.to_output_stream())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user