Add pwd
applet
This commit is contained in:
parent
0453acd0de
commit
091bf713bd
@ -42,16 +42,6 @@ mod which;
|
|||||||
mod whoami;
|
mod whoami;
|
||||||
mod yes;
|
mod yes;
|
||||||
|
|
||||||
#[allow(clippy::module_name_repetitions)]
|
|
||||||
pub use {
|
|
||||||
self::hostname::Hostname, self::shitbox::Shitbox, base32::Base32, base64::Base64,
|
|
||||||
basename::Basename, bootstrap::Bootstrap, chown::Chown, clear::Clear, cut::Cut,
|
|
||||||
dirname::Dirname, echo::Echo, factor::Factor, fold::Fold, groups::Groups, head::Head,
|
|
||||||
link::Link, mountpoint::Mountpoint, nologin::Nologin, nproc::Nproc, r#false::False,
|
|
||||||
r#true::True, rev::Rev, rm::Rm, rmdir::Rmdir, sleep::Sleep, sync::Sync as SyncCmd,
|
|
||||||
unlink::Unlink, which::Which, whoami::Whoami, yes::Yes,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Defines a command or applet, it's cli interface, and it's installation directory
|
/// Defines a command or applet, it's cli interface, and it's installation directory
|
||||||
/// relative to the binary
|
/// relative to the binary
|
||||||
pub trait Cmd: fmt::Debug + Sync {
|
pub trait Cmd: fmt::Debug + Sync {
|
||||||
@ -71,41 +61,42 @@ pub trait Cmd: fmt::Debug + Sync {
|
|||||||
#[allow(clippy::box_default)]
|
#[allow(clippy::box_default)]
|
||||||
pub fn get(name: &str) -> Option<Box<dyn Cmd>> {
|
pub fn get(name: &str) -> Option<Box<dyn Cmd>> {
|
||||||
match name {
|
match name {
|
||||||
"base64" => Some(Box::new(Base64::default())),
|
"base64" => Some(Box::new(base64::Base64::default())),
|
||||||
"base32" => Some(Box::new(Base32::default())),
|
"base32" => Some(Box::new(base32::Base32::default())),
|
||||||
"basename" => Some(Box::new(Basename::default())),
|
"basename" => Some(Box::new(basename::Basename::default())),
|
||||||
"bootstrap" => Some(Box::new(Bootstrap::default())),
|
"bootstrap" => Some(Box::new(bootstrap::Bootstrap::default())),
|
||||||
"chmod" => Some(Box::new(chmod::Chmod::default())),
|
"chmod" => Some(Box::new(chmod::Chmod::default())),
|
||||||
"chown" => Some(Box::new(chown::Chown::default())),
|
"chown" => Some(Box::new(chown::Chown::default())),
|
||||||
"clear" => Some(Box::new(Clear::default())),
|
"clear" => Some(Box::new(clear::Clear::default())),
|
||||||
"cut" => Some(Box::new(Cut::default())),
|
"cut" => Some(Box::new(cut::Cut::default())),
|
||||||
"dirname" => Some(Box::new(Dirname::default())),
|
"dirname" => Some(Box::new(dirname::Dirname::default())),
|
||||||
"echo" => Some(Box::new(Echo::default())),
|
"echo" => Some(Box::new(echo::Echo::default())),
|
||||||
"factor" => Some(Box::new(Factor::default())),
|
"factor" => Some(Box::new(factor::Factor::default())),
|
||||||
"false" => Some(Box::new(False::default())),
|
"false" => Some(Box::new(r#false::False::default())),
|
||||||
"fold" => Some(Box::new(Fold::default())),
|
"fold" => Some(Box::new(fold::Fold::default())),
|
||||||
"groups" => Some(Box::new(Groups::default())),
|
"groups" => Some(Box::new(groups::Groups::default())),
|
||||||
"head" => Some(Box::new(Head::default())),
|
"head" => Some(Box::new(head::Head::default())),
|
||||||
"link" => Some(Box::new(Link::default())),
|
"link" => Some(Box::new(link::Link::default())),
|
||||||
"mountpoint" => Some(Box::new(Mountpoint::default())),
|
"mountpoint" => Some(Box::new(mountpoint::Mountpoint::default())),
|
||||||
"nologin" => Some(Box::new(Nologin::default())),
|
"nologin" => Some(Box::new(nologin::Nologin::default())),
|
||||||
"nproc" => Some(Box::new(Nproc::default())),
|
"nproc" => Some(Box::new(nproc::Nproc::default())),
|
||||||
"rev" => Some(Box::new(Rev::default())),
|
"pwd" => Some(Box::new(pwd::Pwd::default())),
|
||||||
"rm" => Some(Box::new(Rm::default())),
|
"rev" => Some(Box::new(rev::Rev::default())),
|
||||||
"rmdir" => Some(Box::new(Rmdir::default())),
|
"rm" => Some(Box::new(rm::Rm::default())),
|
||||||
"shitbox" => Some(Box::new(Shitbox::default())),
|
"rmdir" => Some(Box::new(rmdir::Rmdir::default())),
|
||||||
"sleep" => Some(Box::new(Sleep::default())),
|
"shitbox" => Some(Box::new(shitbox::Shitbox::default())),
|
||||||
"sync" => Some(Box::new(SyncCmd::default())),
|
"sleep" => Some(Box::new(sleep::Sleep::default())),
|
||||||
"true" => Some(Box::new(True::default())),
|
"sync" => Some(Box::new(sync::Sync::default())),
|
||||||
"unlink" => Some(Box::new(Unlink::default())),
|
"true" => Some(Box::new(r#true::True::default())),
|
||||||
"which" => Some(Box::new(Which::default())),
|
"unlink" => Some(Box::new(unlink::Unlink::default())),
|
||||||
"whoami" => Some(Box::new(Whoami::default())),
|
"which" => Some(Box::new(which::Which::default())),
|
||||||
"yes" => Some(Box::new(Yes::default())),
|
"whoami" => Some(Box::new(whoami::Whoami::default())),
|
||||||
|
"yes" => Some(Box::new(yes::Yes::default())),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static COMMANDS: [&str; 31] = [
|
pub static COMMANDS: [&str; 32] = [
|
||||||
"base32",
|
"base32",
|
||||||
"base64",
|
"base64",
|
||||||
"basename",
|
"basename",
|
||||||
@ -126,6 +117,7 @@ pub static COMMANDS: [&str; 31] = [
|
|||||||
"mountpoint",
|
"mountpoint",
|
||||||
"nologin",
|
"nologin",
|
||||||
"nproc",
|
"nproc",
|
||||||
|
"pwd",
|
||||||
"rev",
|
"rev",
|
||||||
"rm",
|
"rm",
|
||||||
"rmdir",
|
"rmdir",
|
||||||
|
@ -1 +1,47 @@
|
|||||||
|
use super::Cmd;
|
||||||
|
use clap::{Arg, ArgAction, Command};
|
||||||
|
use std::{env, io, path::PathBuf};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Pwd;
|
||||||
|
|
||||||
|
impl Cmd for Pwd {
|
||||||
|
fn cli(&self) -> clap::Command {
|
||||||
|
Command::new("pwd")
|
||||||
|
.about("return working directory name")
|
||||||
|
.author("Nathan Fisher")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.args([
|
||||||
|
Arg::new("logical")
|
||||||
|
.short('L')
|
||||||
|
.long("logical")
|
||||||
|
.help("use PWD from environment, even if it contains symlinks")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
Arg::new("physical")
|
||||||
|
.short('P')
|
||||||
|
.long("physical")
|
||||||
|
.help("avoid all symlinks")
|
||||||
|
.conflicts_with("logical")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
};
|
||||||
|
let cwd = if matches.get_flag("logical") {
|
||||||
|
PathBuf::from(env::var("PWD")?)
|
||||||
|
} else if matches.get_flag("physical") {
|
||||||
|
env::current_dir()?.canonicalize()?
|
||||||
|
} else {
|
||||||
|
env::current_dir()?
|
||||||
|
};
|
||||||
|
println!("{}", cwd.display());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path(&self) -> Option<crate::Path> {
|
||||||
|
Some(crate::Path::UsrBin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user