change-user-run 0.1.3

Run commands as other users and create users
Documentation
//! A simple example on how to get a command in PATH.
//!
//! # Note
//!
//! This is a very basic example used in containerized integration tests of this project.
//! As such, it is probably not very useful on its own.

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 {
    /// The command to search for in PATH.
    #[arg(help = "The command to search for in PATH.")]
    pub command: String,
}

/// Initializes a logger.
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.");
    }
}

/// Runs the example application.
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
        }
    }
}