Make echo more flexible with data types

This commit is contained in:
Jonathan Turner 2019-11-02 08:15:53 +13:00
parent e75fdc2865
commit a3679f0f4e

View File

@ -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); output.push(Ok(ReturnSuccess::Value(i.clone())));
} }
_ => { },
return Err(ShellError::type_error(
"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())
} }