diff --git a/src/uu/pwdx/src/pwdx.rs b/src/uu/pwdx/src/pwdx.rs index a5f5652..c38e403 100644 --- a/src/uu/pwdx/src/pwdx.rs +++ b/src/uu/pwdx/src/pwdx.rs @@ -3,6 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +use clap::Arg; use clap::{crate_version, Command}; use std::env; use std::fs; @@ -16,14 +17,15 @@ const USAGE: &str = help_usage!("pwdx.md"); #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args: Vec = env::args().collect(); - if args.len() != 2 { - eprintln!("Usage: pwdx "); + let matches = uu_app().try_get_matches_from(args)?; + + let pid_str = matches.get_one::("pid").unwrap(); + let pid = pid_str.parse::().unwrap_or_else(|_| { + eprintln!("Invalid PID"); process::exit(1); - } + }); - let pid = &args[1]; let cwd_link = format!("/proc/{}/cwd", pid); match fs::read_link(Path::new(&cwd_link)) { @@ -42,4 +44,9 @@ pub fn uu_app() -> Command { .about(ABOUT) .override_usage(format_usage(USAGE)) .infer_long_args(true) + .arg(Arg::new("pid") + .value_name("PID") + .help("Process ID") + .required(true) + .index(1)) } diff --git a/src/uu/renice/src/renice.rs b/src/uu/renice/src/renice.rs index 50582e0..6d156ad 100644 --- a/src/uu/renice/src/renice.rs +++ b/src/uu/renice/src/renice.rs @@ -7,7 +7,6 @@ use libc::PRIO_PROCESS; use std::env; use std::io::Error; use std::process; -use std::str::FromStr; use uucore::{error::UResult, format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("renice.md"); const USAGE: &str = help_usage!("renice.md");