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,
_raw_args: &RawCommandArgs,
) -> Result<OutputStream, ShellError> {
let name = call_info.name_tag.clone();
let mut output = String::new();
let mut first = true;
let mut output = vec![];
if let Some(ref positional) = call_info.args.positional {
for i in positional {
match i.as_string() {
Ok(s) => {
if !first {
output.push_str(" ");
} else {
first = false;
output.push(Ok(ReturnSuccess::Value(
Value::string(s).tagged(i.tag.clone()),
)));
}
_ => 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(
"a string-compatible value",
i.tagged_type_name(),
))
}
_ => {
output.push(Ok(ReturnSuccess::Value(i.clone())));
}
},
}
}
}
let stream = VecDeque::from(vec![Ok(ReturnSuccess::Value(
Value::string(output).tagged(name),
))]);
let stream = VecDeque::from(output);
Ok(stream.to_output_stream())
}