feat: add the yes command
This commit is contained in:
parent
47f5cfb674
commit
be4cbd760b
3 changed files with 27 additions and 0 deletions
|
|
@ -14,3 +14,4 @@ command!(nproc::Nproc);
|
|||
command!(r#true::True);
|
||||
command!(r#false::False);
|
||||
command!(test::Test);
|
||||
command!(yes::Yes);
|
||||
|
|
|
|||
25
coreutils/src/commands/yes.rs
Normal file
25
coreutils/src/commands/yes.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue