use std::process::ExitCode;
use change_user_run::get_command;
use clap::Parser;
use log::{LevelFilter, debug, error};
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};
#[derive(Debug, Parser)]
#[command(about = "Returns the absolute path of a command in PATH", version)]
struct Cli {
#[arg(help = "The command to search for in PATH.")]
pub command: String,
}
fn init_logger() {
if TermLogger::init(
LevelFilter::Debug,
Config::default(),
TerminalMode::Stderr,
ColorChoice::Auto,
)
.is_err()
{
eprintln!("Not initializing another logger, as one is initialized already.");
}
}
fn main() -> ExitCode {
init_logger();
let cli = Cli::parse();
debug!("Return the absolute path of command {}", cli.command);
match get_command(&cli.command) {
Ok(path) => {
println!("{}", path.into_os_string().as_os_str().to_string_lossy());
ExitCode::SUCCESS
}
Err(error) => {
error!("{error}");
ExitCode::FAILURE
}
}
}