shitbox/src/lib.rs

39 lines
895 B
Rust

#![warn(clippy::all, clippy::pedantic)]
use std::{env, path::PathBuf, string::ToString};
mod cli;
pub mod cmd;
pub enum Path {
Bin,
Sbin,
UsrBin,
UsrSbin,
}
#[must_use]
pub fn progname() -> Option<String> {
env::args()
.next()
.and_then(|x| {
PathBuf::from(x)
.file_name()
.map(|x| x.to_str().map(ToString::to_string))
})
.flatten()
}
pub fn run() {
if let Some(progname) = progname() {
match progname.as_str() {
"echo" => cmd::echo::run(),
"false" => cmd::r#false::run(),
"head" => cmd::head::run(&cmd::head::cli().get_matches()),
"hostname" => cmd::hostname::run(&cmd::hostname::cli().get_matches()),
"true" => cmd::r#true::run(),
"shitbox" => cli::run(),
_ => unimplemented!(),
}
}
}