From be4cbd760bf1a57eed8c50b7288a7651be61eca4 Mon Sep 17 00:00:00 2001 From: teesh3rt Date: Mon, 24 Mar 2025 20:18:24 +0200 Subject: [PATCH] feat: add the yes command --- coreutils/src/commands/mod.rs | 1 + coreutils/src/commands/yes.rs | 25 +++++++++++++++++++++++++ src/registry.rs | 1 + 3 files changed, 27 insertions(+) create mode 100644 coreutils/src/commands/yes.rs diff --git a/coreutils/src/commands/mod.rs b/coreutils/src/commands/mod.rs index 3464b27..f0ef483 100644 --- a/coreutils/src/commands/mod.rs +++ b/coreutils/src/commands/mod.rs @@ -14,3 +14,4 @@ command!(nproc::Nproc); command!(r#true::True); command!(r#false::False); command!(test::Test); +command!(yes::Yes); diff --git a/coreutils/src/commands/yes.rs b/coreutils/src/commands/yes.rs new file mode 100644 index 0000000..14df289 --- /dev/null +++ b/coreutils/src/commands/yes.rs @@ -0,0 +1,25 @@ +use boxutils::args::ArgParser; +use boxutils::commands::Command; + +pub struct Yes; + +impl Command for Yes { + fn execute(&self) { + let args = ArgParser::builder().add_flag("--help").parse_args("yes"); + + if args.get_flag("--help") { + println!("Usage: yes [STRING]"); + return; + } + + let string = if args.get_normal_args().is_empty() { + String::from("y") + } else { + args.get_normal_args().join(" ") + }; + + loop { + println!("{}", string); + } + } +} diff --git a/src/registry.rs b/src/registry.rs index 6a2028a..0e1cbe1 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -18,6 +18,7 @@ pub fn get_registry() -> CommandRegistry { Box::new(coreutils::commands::Test::without_bracket()), ); registry.register("[", Box::new(coreutils::commands::Test::with_bracket())); + registry.register("yes", Box::new(coreutils::commands::Yes)); registry.register("box", Box::new(Boxcmd)); registry