diff --git a/crates/nu-command/src/random/dice.rs b/crates/nu-command/src/random/dice.rs index 6e6ff4296c..9a2e3a2177 100644 --- a/crates/nu-command/src/random/dice.rs +++ b/crates/nu-command/src/random/dice.rs @@ -1,5 +1,5 @@ use nu_engine::command_prelude::*; -use nu_protocol::ListStream; +use nu_protocol::{DeprecationEntry, DeprecationType, ListStream, ReportMode}; use rand::random_range; use std::num::NonZeroUsize; @@ -38,6 +38,16 @@ impl Command for RandomDice { vec!["generate", "die", "1-6"] } + fn deprecation_info(&self) -> Vec { + vec![DeprecationEntry { + ty: DeprecationType::Command, + report_mode: ReportMode::FirstUse, + since: Some("0.107.0".to_owned()), + expected_removal: Some("0.108.0".to_owned()), + help: Some("Use `random dice` from std/random instead.".to_owned()), + }] + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-std/src/lib.rs b/crates/nu-std/src/lib.rs index a1c2240eb8..24ff5a774d 100644 --- a/crates/nu-std/src/lib.rs +++ b/crates/nu-std/src/lib.rs @@ -65,6 +65,7 @@ pub fn load_standard_library( include_str!("../std/testing/mod.nu"), ), ("mod.nu", "std/clip", include_str!("../std/clip/mod.nu")), + ("mod.nu", "std/random", include_str!("../std/random/mod.nu")), ]; for (filename, std_subdir_name, content) in std_submodules.drain(..) { diff --git a/crates/nu-std/std/mod.nu b/crates/nu-std/std/mod.nu index 9c45021f1c..51b55e95d7 100644 --- a/crates/nu-std/std/mod.nu +++ b/crates/nu-std/std/mod.nu @@ -16,6 +16,7 @@ export module std/math export module std/xml export module std/config export module std/testing +export module std/random # Load main dirs command and all subcommands export use std/dirs main diff --git a/crates/nu-std/std/random/mod.nu b/crates/nu-std/std/random/mod.nu new file mode 100644 index 0000000000..1f40cc5b64 --- /dev/null +++ b/crates/nu-std/std/random/mod.nu @@ -0,0 +1,19 @@ +# for examples +alias "random dice" = dice + +# Generate a random dice roll +@search-terms "generate" "die" "1-6" +@example "Roll 1 dice with 6 sides each" { random dice } +@example "Roll 10 dice with 12 sides each" { + random dice --dice 10 --sides 12 +} +export def dice [ + --dice = 1 # The amount of dice being rolled + --sides = 6 # The amount of sides a die has +]: nothing -> list { + mut out = [] + for _ in 1..$dice { + $out ++= [(random int 1..$sides)] + } + $out +}