nushell/crates/nu-command/src/commands/random/uuid.rs
Jonathan Turner 5f550a355b
Split OutputStream into ActionStream/OutputStream (#3304)
* Split OutputStream into ActionStream/OutputStream

* Fmt

* Missed update

* Cleanup helper names

* Fmt
2021-04-12 14:35:01 +12:00

53 lines
1.2 KiB
Rust

use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{ReturnSuccess, Signature};
use uuid_crate::Uuid;
pub struct SubCommand;
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random uuid"
}
fn signature(&self) -> Signature {
Signature::build("random uuid")
}
fn usage(&self) -> &str {
"Generate a random uuid4 string"
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
uuid(args)
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Generate a random uuid4 string",
example: "random uuid",
result: None,
}]
}
}
pub fn uuid(_args: CommandArgs) -> Result<ActionStream, ShellError> {
let uuid_4 = Uuid::new_v4().to_hyphenated().to_string();
Ok(ActionStream::one(ReturnSuccess::value(uuid_4)))
}
#[cfg(test)]
mod tests {
use super::ShellError;
use super::SubCommand;
#[test]
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
test_examples(SubCommand {})
}
}