46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
|
use super::Cmd;
|
||
|
use clap::{Arg, Command};
|
||
|
use std::io;
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub struct Yes {
|
||
|
name: &'static str,
|
||
|
path: Option<crate::Path>,
|
||
|
}
|
||
|
|
||
|
impl Default for Yes {
|
||
|
fn default() -> Self {
|
||
|
Self {
|
||
|
name: "yes",
|
||
|
path: Some(crate::Path::UsrBin),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Cmd for Yes {
|
||
|
fn name(&self) -> &str {
|
||
|
self.name
|
||
|
}
|
||
|
|
||
|
fn cli(&self) -> clap::Command {
|
||
|
Command::new(self.name)
|
||
|
.about("output a string repeatedly until killed")
|
||
|
.author("Nathan Fisher")
|
||
|
.arg(Arg::new("msg").num_args(1).default_value("y"))
|
||
|
}
|
||
|
|
||
|
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||
|
let Some(matches) = matches else {
|
||
|
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
|
||
|
};
|
||
|
let msg = matches.get_one::<String>("msg").unwrap();
|
||
|
loop {
|
||
|
println!("{msg}");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn path(&self) -> Option<crate::Path> {
|
||
|
self.path
|
||
|
}
|
||
|
}
|