mirror of
https://github.com/nushell/nushell.git
synced 2025-05-17 08:20:49 +02:00
* Convert "random bool" to engine-p Also implements FromValue for Tagged<BigDecimal> and Tagged<f64>. * Convert "random dice" to engine-p * Convert "random uuid" to engine-p * Covert "random chars" to engine-p * Convert "random" command to engine-p
53 lines
1.1 KiB
Rust
53 lines
1.1 KiB
Rust
use crate::prelude::*;
|
|
use nu_engine::WholeStreamCommand;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::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(&self, args: CommandArgs) -> Result<OutputStream, 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<OutputStream, ShellError> {
|
|
let uuid_4 = Uuid::new_v4().to_hyphenated().to_string();
|
|
|
|
Ok(OutputStream::one(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 {})
|
|
}
|
|
}
|