feat: add the yes command

This commit is contained in:
Teesh 2025-03-24 20:18:24 +02:00
parent 47f5cfb674
commit be4cbd760b
3 changed files with 27 additions and 0 deletions

View file

@ -14,3 +14,4 @@ command!(nproc::Nproc);
command!(r#true::True); command!(r#true::True);
command!(r#false::False); command!(r#false::False);
command!(test::Test); command!(test::Test);
command!(yes::Yes);

View file

@ -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);
}
}
}

View file

@ -18,6 +18,7 @@ pub fn get_registry() -> CommandRegistry {
Box::new(coreutils::commands::Test::without_bracket()), Box::new(coreutils::commands::Test::without_bracket()),
); );
registry.register("[", Box::new(coreutils::commands::Test::with_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.register("box", Box::new(Boxcmd));
registry registry