2020-05-04 10:44:33 +02:00
|
|
|
use crate::prelude::*;
|
2021-01-10 03:50:49 +01:00
|
|
|
use nu_engine::WholeStreamCommand;
|
2020-05-04 10:44:33 +02:00
|
|
|
use nu_errors::ShellError;
|
2020-05-16 05:18:24 +02:00
|
|
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
|
2020-05-04 10:44:33 +02:00
|
|
|
|
2020-05-16 05:18:24 +02:00
|
|
|
#[derive(Clone)]
|
2020-05-04 10:44:33 +02:00
|
|
|
pub struct To;
|
|
|
|
|
2020-05-29 10:22:52 +02:00
|
|
|
#[async_trait]
|
2020-05-04 10:44:33 +02:00
|
|
|
impl WholeStreamCommand for To {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"to"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("to")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
2020-05-04 23:00:29 +02:00
|
|
|
"Convert table into an output format (based on subcommand, like csv, html, json, yaml)."
|
2020-05-04 10:44:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 08:53:49 +01:00
|
|
|
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
2020-06-13 10:43:21 +02:00
|
|
|
Ok(OutputStream::one(ReturnSuccess::value(
|
2021-01-10 03:50:49 +01:00
|
|
|
UntaggedValue::string(get_help(&To, &args.scope)).into_value(Tag::unknown()),
|
2020-06-13 10:43:21 +02:00
|
|
|
)))
|
2020-05-04 10:44:33 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-18 14:56:01 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-10-03 16:06:02 +02:00
|
|
|
use super::ShellError;
|
2020-05-18 14:56:01 +02:00
|
|
|
use super::To;
|
|
|
|
|
|
|
|
#[test]
|
2020-10-03 16:06:02 +02:00
|
|
|
fn examples_work_as_expected() -> Result<(), ShellError> {
|
2020-05-18 14:56:01 +02:00
|
|
|
use crate::examples::test as test_examples;
|
|
|
|
|
2021-02-12 11:13:14 +01:00
|
|
|
test_examples(To {})
|
2020-05-18 14:56:01 +02:00
|
|
|
}
|
|
|
|
}
|