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