1use clap::Parser;
2use nothing::Probably;
3use std::env;
4use std::path::{Path, PathBuf};
5
6pub fn locate<P>(exe_name: P) -> Option<PathBuf>
10where
11 P: AsRef<Path>,
12{
13 env::var_os("PATH").and_then(|paths| {
14 env::split_paths(&paths)
15 .filter_map(|dir| {
16 let full_path = dir.join(&exe_name);
17 if full_path.is_file() {
18 Some(full_path)
19 } else {
20 None
21 }
22 })
23 .next()
24 })
25}
26
27#[derive(Parser)]
29#[clap(author, version, about, long_about = None)]
30pub struct Args {
31 pub command: String,
33}
34
35impl Args {
36 pub fn locate(self) -> Probably<PathBuf> {
38 locate(self.command).into()
39 }
40}