Change Cmd::Run
signature to take &clap::Options
instead of
`Option<&clap::Options>` - saves 10k
This commit is contained in:
parent
5fd1bb1220
commit
6b30c356dd
@ -20,10 +20,7 @@ impl Cmd for Base32 {
|
||||
.args(args())
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "No input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let color = match matches.get_one::<String>("color").map(String::as_str) {
|
||||
Some("always") => ColorChoice::Always,
|
||||
Some("ansi") => ColorChoice::AlwaysAnsi,
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Base64 {
|
||||
.args(args())
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "No input")));
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let color = match matches.get_one::<String>("color").map(String::as_str) {
|
||||
Some("always") => ColorChoice::Always,
|
||||
Some("ansi") => ColorChoice::AlwaysAnsi,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgMatches, Command};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Basename;
|
||||
@ -26,10 +25,7 @@ impl Cmd for Basename {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(mut base) = matches
|
||||
.get_one::<String>("NAME")
|
||||
.and_then(|x| x.split('/').last())
|
||||
|
@ -5,8 +5,7 @@ use clap_complete_nushell::Nushell;
|
||||
use clap_mangen::Man;
|
||||
use std::{
|
||||
error::Error,
|
||||
fs,
|
||||
io::{self, ErrorKind},
|
||||
fs, io,
|
||||
os::unix::fs::symlink,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@ -152,10 +151,7 @@ impl Cmd for Bootstrap {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(ErrorKind::Other, "No input").into());
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(prefix) = matches.get_one::<String>("prefix") {
|
||||
let usr = matches.get_flag("usr");
|
||||
if let Some(progpath) = crate::progpath() {
|
||||
|
@ -43,10 +43,7 @@ impl Cmd for Chmod {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let feedback = Feedback::from_matches(matches);
|
||||
let mode = matches
|
||||
.get_one::<String>("mode")
|
||||
|
@ -36,10 +36,7 @@ impl Cmd for Chgrp {
|
||||
)
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let recurse = Recurse::from_matches(matches);
|
||||
let feedback = Feedback::from_matches(matches);
|
||||
let group = if let Some(grp) = matches.get_one::<String>("group") {
|
||||
|
@ -38,10 +38,7 @@ impl Cmd for Chown {
|
||||
)
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let recurse = Recurse::from_matches(matches);
|
||||
let feedback = Feedback::from_matches(matches);
|
||||
let (user, group) = if let Some(who) = matches.get_one::<String>("user") {
|
||||
|
@ -38,10 +38,7 @@ impl Cmd for Chroot {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(newroot) = matches.get_one::<String>("newroot") else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no new root given").into());
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ impl Cmd for Clear {
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
print!("\x1b[2J\x1b[H");
|
||||
print!("\x1b[3J\x1b[H");
|
||||
Ok(())
|
||||
|
@ -63,10 +63,7 @@ impl Cmd for Cut {
|
||||
)
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let files: Vec<String> = match matches.get_many::<String>("file") {
|
||||
Some(f) => f.cloned().collect(),
|
||||
None => vec!["-".to_string()],
|
||||
|
@ -19,8 +19,7 @@ impl Cmd for Dirname {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(matches) = matches {
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(names) = matches.get_many::<String>("name") {
|
||||
names.for_each(|name| {
|
||||
let path = match Path::new(name).parent() {
|
||||
@ -40,7 +39,6 @@ impl Cmd for Dirname {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl Cmd for Echo {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let idx = match crate::progname() {
|
||||
Some(s) if s.as_str() == "echo" => 1,
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::io;
|
||||
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgAction, Command, ValueHint};
|
||||
|
||||
@ -40,10 +38,7 @@ impl Cmd for Expand {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,7 @@ impl Cmd for Factor {
|
||||
)
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(matches) = matches {
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
match matches.get_many::<u64>("number") {
|
||||
Some(numbers) => {
|
||||
numbers.for_each(|n| print_factors(*n));
|
||||
@ -38,7 +37,6 @@ impl Cmd for Factor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ impl Cmd for False {
|
||||
.author("Nathan Fisher")
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,7 @@ impl Cmd for Fold {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let files = match matches.get_many::<String>("FILE") {
|
||||
Some(c) => c.map(String::to_string).collect(),
|
||||
None => vec!["-".to_string()],
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::Cmd;
|
||||
use crate::pw;
|
||||
use clap::{Arg, Command};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Groups;
|
||||
@ -21,10 +20,7 @@ impl Cmd for Groups {
|
||||
.arg(Arg::new("user"))
|
||||
}
|
||||
|
||||
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")))
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let groups = match matches.get_one::<String>("user") {
|
||||
Some(u) => pw::get_group_names_for_name(u)?,
|
||||
None => pw::get_group_names()?,
|
||||
|
@ -5,7 +5,7 @@ use std::{
|
||||
env,
|
||||
error::Error,
|
||||
fs,
|
||||
io::{self, stdin, Read, Write},
|
||||
io::{stdin, Read, Write},
|
||||
};
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||
|
||||
@ -57,7 +57,7 @@ impl Cmd for Head {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let idx = match crate::progname() {
|
||||
Some(s) if s.as_str() == "head" => 1,
|
||||
@ -80,9 +80,6 @@ impl Cmd for Head {
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "No input").into());
|
||||
};
|
||||
if let Some(l) = matches.get_one("LINES") {
|
||||
lines = *l;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ impl Cmd for Hostid {
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let hostid = unsafe { libc::gethostid() };
|
||||
let hostid: String = format!("{hostid:x}").chars().skip(8).collect();
|
||||
println!("{}", hostid);
|
||||
|
@ -22,8 +22,7 @@ impl Cmd for Hostname {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let matches = matches.unwrap();
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(name) = matches.get_one::<String>("NAME") {
|
||||
unistd::sethostname(name)?;
|
||||
Ok(())
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Link {
|
||||
])
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(f1) = matches.get_one::<String>("file1") else {
|
||||
return Err(Box::new(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
|
@ -14,7 +14,7 @@ impl Cmd for Logname {
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let logname = unsafe { CStr::from_ptr(libc::getlogin()) };
|
||||
let logname = logname.to_str()?;
|
||||
println!("{logname}");
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Md5sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::Cmd;
|
||||
use crate::{args, mode::Parser, stat};
|
||||
use clap::{Arg, ArgMatches, Command};
|
||||
use std::{error::Error, io};
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MkFifo;
|
||||
@ -35,10 +35,7 @@ impl Cmd for MkFifo {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let mode = if let Some(m) = matches.get_one::<String>("mode") {
|
||||
Parser::new(0o666).parse(m)?
|
||||
} else {
|
||||
|
@ -40,10 +40,7 @@ impl Cmd for MkNod {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let Some(file) = matches.get_one::<String>("file") else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no file given").into());
|
||||
};
|
||||
|
@ -36,10 +36,7 @@ impl Cmd for MkTemp {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut path = if let Some(t) = matches.get_one::<String>("tmpdir") {
|
||||
PathBuf::from(t)
|
||||
} else {
|
||||
|
@ -67,7 +67,7 @@ pub trait Cmd: fmt::Debug + Sync {
|
||||
/// Runs the applet
|
||||
/// # Errors
|
||||
/// Bubbles up any errors to the caller
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>>;
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>>;
|
||||
/// Returns the path relative to the binary where the link to this applet
|
||||
/// will be installed
|
||||
fn path(&self) -> Option<crate::Path>;
|
||||
|
@ -55,10 +55,7 @@ impl Cmd for Mountpoint {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let file = matches.get_one::<String>("file").unwrap();
|
||||
if matches.get_flag("fs-devno") {
|
||||
if let Some(maj_min) = fs_devno(file)? {
|
||||
|
@ -12,7 +12,7 @@ impl Cmd for Nologin {
|
||||
.about("Denies a user account login ability")
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
eprintln!("I'm sorry, I can't let you do that, Dave");
|
||||
process::exit(42);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Nproc;
|
||||
@ -19,10 +18,7 @@ impl Cmd for Nproc {
|
||||
)
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if matches.get_flag("ALL") {
|
||||
println!("{}", unsafe { get_nprocs_conf() });
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{env, io};
|
||||
use std::env;
|
||||
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
@ -25,10 +25,7 @@ impl Cmd for Printenv {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(vars) = matches.get_many::<String>("var") {
|
||||
for var in vars {
|
||||
let val = env::var(var)?;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::{env, io, path::PathBuf};
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Pwd;
|
||||
@ -26,10 +26,7 @@ impl Cmd for Pwd {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cwd = if matches.get_flag("logical") {
|
||||
PathBuf::from(env::var("PWD")?)
|
||||
} else if matches.get_flag("physical") {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::Cmd;
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command, ValueHint};
|
||||
use std::{fs, io, path::PathBuf};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Readlink;
|
||||
@ -31,10 +31,7 @@ impl Cmd for Readlink {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(paths) = matches.get_many::<String>("path") {
|
||||
let paths: Vec<_> = paths.collect();
|
||||
let len = paths.len();
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::Cmd;
|
||||
use clap::{Arg, ArgAction, Command, ValueHint};
|
||||
use std::{env, fs, io, process};
|
||||
use std::{env, fs, process};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Realpath;
|
||||
@ -24,10 +24,7 @@ impl Cmd for Realpath {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("path") {
|
||||
let mut erred = false;
|
||||
for f in files {
|
||||
|
@ -3,7 +3,7 @@ use crate::args;
|
||||
use clap::{Arg, Command};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, BufRead, BufReader, ErrorKind, Write},
|
||||
io::{self, BufRead, BufReader, Write},
|
||||
};
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||
|
||||
@ -25,10 +25,7 @@ impl Cmd for Rev {
|
||||
])
|
||||
}
|
||||
|
||||
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(ErrorKind::Other, "No input")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let color = match matches.get_one::<String>("color").map(String::as_str) {
|
||||
Some("always") => ColorChoice::Always,
|
||||
Some("ansi") => ColorChoice::AlwaysAnsi,
|
||||
|
@ -62,10 +62,7 @@ impl Cmd for Rm {
|
||||
)
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut actions = AllActions::from(matches);
|
||||
let proceed = match actions.prompt {
|
||||
When::Always => true,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::Cmd;
|
||||
use crate::args;
|
||||
use clap::{Arg, ArgAction, Command, ValueHint};
|
||||
use std::{error::Error, fs, io, path::Path};
|
||||
use std::{error::Error, fs, path::Path};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Rmdir;
|
||||
@ -27,10 +27,7 @@ impl Cmd for Rmdir {
|
||||
])
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(directories) = matches.get_many::<String>("dir") {
|
||||
for dir in directories {
|
||||
if matches.get_flag("parents") {
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Sha1sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Sha224sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Sha256sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Sha384sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -19,10 +19,7 @@ impl Cmd for Sha512sum {
|
||||
.args([args::check(), args::file()])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
let mut erred = 0;
|
||||
for f in files {
|
||||
|
@ -1,10 +1,6 @@
|
||||
use super::{Cmd, COMMANDS};
|
||||
use clap::Command;
|
||||
use std::{
|
||||
error::Error,
|
||||
io::{self, ErrorKind},
|
||||
process,
|
||||
};
|
||||
use std::{error::Error, process};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Shitbox;
|
||||
@ -33,13 +29,10 @@ impl Cmd for Shitbox {
|
||||
.subcommands(&subcommands)
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(ErrorKind::Other, "No input")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
if let Some((name, matches)) = matches.subcommand() {
|
||||
if let Some(command) = crate::cmd::get(name) {
|
||||
if let Err(e) = command.run(Some(matches)) {
|
||||
if let Err(e) = command.run(matches) {
|
||||
eprintln!("Error: {name}: {e}");
|
||||
process::exit(1);
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ impl Cmd for Sleep {
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(raw) = matches.unwrap().get_one::<f64>("seconds") {
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(raw) = matches.get_one::<f64>("seconds") {
|
||||
let seconds = *raw as u64;
|
||||
let nanos = ((raw % 1.0) * 10e-9) as u32;
|
||||
let s = Duration::new(seconds, nanos);
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::unistd;
|
||||
|
||||
use super::Cmd;
|
||||
use crate::unistd;
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::{error::Error, fs::OpenOptions, io};
|
||||
use std::{error::Error, fs::OpenOptions};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Sync;
|
||||
@ -34,10 +33,7 @@ impl Cmd for Sync {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("FILE") {
|
||||
for f in files {
|
||||
let mut opts = OpenOptions::new();
|
||||
|
@ -13,7 +13,7 @@ impl Cmd for True {
|
||||
.author("Nathan Fisher")
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::Cmd;
|
||||
use crate::{args, unistd};
|
||||
use clap::{Arg, Command};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Unlink;
|
||||
@ -21,10 +20,7 @@ impl Cmd for Unlink {
|
||||
])
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(files) = matches.get_many::<String>("file") {
|
||||
for f in files {
|
||||
unistd::unlink(f)?;
|
||||
|
@ -6,7 +6,7 @@ use std::{
|
||||
error::Error,
|
||||
fmt::{self, Write},
|
||||
fs,
|
||||
io::{self, stdin, Read},
|
||||
io::{stdin, Read},
|
||||
ops::{AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign},
|
||||
str::FromStr,
|
||||
};
|
||||
@ -52,10 +52,7 @@ impl Cmd for Wc {
|
||||
])
|
||||
}
|
||||
|
||||
fn run(&self, matches: Option<&ArgMatches>) -> Result<(), Box<dyn Error>> {
|
||||
let Some(matches) = matches else {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||
};
|
||||
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
let mut flags = 0;
|
||||
for arg in &["LINES", "WORDS", "CHARS", "BYTES", "MAX"] {
|
||||
if matches.get_flag(arg) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::Cmd;
|
||||
use crate::{bitflags::BitFlags, mode::Bit};
|
||||
use clap::{Arg, Command};
|
||||
use std::{env, fs::File, io, os::unix::prelude::MetadataExt, path::PathBuf, process};
|
||||
use std::{env, fs::File, os::unix::prelude::MetadataExt, path::PathBuf, process};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Which;
|
||||
@ -15,10 +15,7 @@ impl Cmd for Which {
|
||||
.arg(Arg::new("COMMAND").num_args(1..))
|
||||
}
|
||||
|
||||
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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let rawpath = if let Ok(p) = env::var("PATH") {
|
||||
p
|
||||
} else {
|
||||
@ -31,7 +28,7 @@ impl Cmd for Which {
|
||||
if let Some(p) = which(command, &path) {
|
||||
println!("{p}");
|
||||
} else {
|
||||
println!("which: no {} in ({})", command, &rawpath);
|
||||
println!("which: no {command} in ({})", &rawpath);
|
||||
failures += 1;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ impl Cmd for Whoami {
|
||||
.author("Nathan Fisher")
|
||||
}
|
||||
|
||||
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let pwnam = unsafe {
|
||||
let pw = *getpwuid(geteuid());
|
||||
CStr::from_ptr((pw).pw_name)
|
||||
|
@ -1,6 +1,5 @@
|
||||
use super::Cmd;
|
||||
use clap::{Arg, Command};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Yes;
|
||||
@ -13,10 +12,7 @@ impl Cmd for Yes {
|
||||
.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")));
|
||||
};
|
||||
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let msg = matches.get_one::<String>("msg").unwrap();
|
||||
loop {
|
||||
println!("{msg}");
|
||||
|
@ -12,7 +12,6 @@ use {
|
||||
};
|
||||
|
||||
pub enum HashType {
|
||||
Blake2b,
|
||||
Md5,
|
||||
Sha1,
|
||||
Sha224,
|
||||
@ -54,7 +53,6 @@ pub fn check_sums(file: &str, hashtype: HashType, erred: &mut usize) -> Result<(
|
||||
io::Error::new(io::ErrorKind::Other, "invalid checksum file").into(),
|
||||
)?;
|
||||
let s = match hashtype {
|
||||
HashType::Blake2b => unimplemented!(),
|
||||
HashType::Md5 => compute_hash(file, Md5::new())?,
|
||||
HashType::Sha1 => compute_hash(file, Sha1::new())?,
|
||||
HashType::Sha224 => compute_hash(file, Sha224::new())?,
|
||||
|
@ -68,7 +68,7 @@ pub fn run() {
|
||||
if let Some(progname) = progname() {
|
||||
if let Some(command) = cmd::get(&progname) {
|
||||
let cli = command.cli();
|
||||
if let Err(e) = command.run(Some(&cli.get_matches())) {
|
||||
if let Err(e) = command.run(&cli.get_matches()) {
|
||||
eprintln!("{progname}: Error: {e}");
|
||||
process::exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user