Added yes
applet
This commit is contained in:
parent
3857265728
commit
991e19bcbc
@ -29,11 +29,13 @@ pub mod shitbox;
|
|||||||
pub mod sleep;
|
pub mod sleep;
|
||||||
mod sync;
|
mod sync;
|
||||||
pub mod r#true;
|
pub mod r#true;
|
||||||
|
pub mod yes;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
self::hostname::Hostname, base32::Base32, base64::Base64, bootstrap::Bootstrap,
|
self::hostname::Hostname, base32::Base32, base64::Base64, bootstrap::Bootstrap,
|
||||||
dirname::Dirname, echo::Echo, factor::Factor, head::Head, mountpoint::Mountpoint,
|
dirname::Dirname, echo::Echo, factor::Factor, head::Head, mountpoint::Mountpoint,
|
||||||
nologin::Nologin, r#false::False, r#true::True, rev::Rev, shitbox::Shitbox, sleep::Sleep,
|
nologin::Nologin, r#false::False, r#true::True, rev::Rev, shitbox::Shitbox, sleep::Sleep,
|
||||||
|
yes::Yes,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait Cmd: fmt::Debug + Sync {
|
pub trait Cmd: fmt::Debug + Sync {
|
||||||
@ -59,11 +61,12 @@ pub fn get(name: &str) -> Option<Box<dyn Cmd>> {
|
|||||||
"shitbox" => Some(Box::new(Shitbox::default())),
|
"shitbox" => Some(Box::new(Shitbox::default())),
|
||||||
"sleep" => Some(Box::new(Sleep::default())),
|
"sleep" => Some(Box::new(Sleep::default())),
|
||||||
"true" => Some(Box::new(True::default())),
|
"true" => Some(Box::new(True::default())),
|
||||||
|
"yes" => Some(Box::new(Yes::default())),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static COMMANDS: [&'static str; 15] = [
|
pub static COMMANDS: [&'static str; 16] = [
|
||||||
"base32",
|
"base32",
|
||||||
"base64",
|
"base64",
|
||||||
"bootstrap",
|
"bootstrap",
|
||||||
@ -79,4 +82,5 @@ pub static COMMANDS: [&'static str; 15] = [
|
|||||||
"sleep",
|
"sleep",
|
||||||
"shitbox",
|
"shitbox",
|
||||||
"true",
|
"true",
|
||||||
|
"yes",
|
||||||
];
|
];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::Cmd;
|
use crate::Cmd;
|
||||||
use clap::{Arg, Command, ArgAction};
|
use clap::{Arg, ArgAction, Command};
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, BufRead, BufReader, ErrorKind, Write},
|
io::{self, BufRead, BufReader, ErrorKind, Write},
|
||||||
|
45
src/cmd/yes/mod.rs
Normal file
45
src/cmd/yes/mod.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user