2023-01-20 22:46:16 -05:00
|
|
|
use super::Cmd;
|
|
|
|
use clap::{Arg, ArgAction, Command};
|
2023-02-04 08:54:27 -05:00
|
|
|
use std::{env, path::PathBuf};
|
2022-12-20 12:05:21 -05:00
|
|
|
|
2023-04-17 23:27:57 -04:00
|
|
|
#[derive(Debug)]
|
2023-01-20 22:46:16 -05:00
|
|
|
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),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
2023-01-20 22:46:16 -05:00
|
|
|
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(())
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:50:59 -05:00
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
|
|
Some(shitbox::Path::UsrBin)
|
2023-01-20 22:46:16 -05:00
|
|
|
}
|
|
|
|
}
|