rfham-cli 0.1.1

CLI for accessing RF-Ham tools.
use crate::{OnceCommand, error::CliError};
use colorchoice::ColorChoice;
use std::process::ExitCode;
use tracing::info;

// ------------------------------------------------------------------------------------------------
// Public Types
// ------------------------------------------------------------------------------------------------

#[derive(Debug, Default)]
pub struct RunExternalSubCommand {
    command_name: String,
    arguments: Vec<String>,
    verbosity: u8,
    quietness: u8,
    color_choice: ColorChoice,
}

// ------------------------------------------------------------------------------------------------
// Implementations
// ------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------

impl RunExternalSubCommand {
    pub fn new(command_name: String, arguments: &[String]) -> Self {
        Self {
            command_name,
            arguments: arguments.to_vec(),
            verbosity: 0,
            quietness: 0,
            color_choice: ColorChoice::Auto,
        }
    }

    pub fn with_verbosity_level(mut self, verbosity: u8) -> Self {
        self.verbosity = verbosity;
        self
    }
    pub fn with_quietness_level(mut self, quietness: u8) -> Self {
        self.quietness = quietness;
        self
    }
    pub fn with_color_choice(mut self, color_choice: ColorChoice) -> Self {
        self.color_choice = color_choice;
        self
    }
}

impl OnceCommand for RunExternalSubCommand {
    type Output = ExitCode;
    type Error = CliError;

    fn execute(self) -> Result<Self::Output, Self::Error> {
        let mut arguments = Vec::new();
        if self.verbosity > 0 {
            arguments.push(format!("-{}", "v".repeat(self.verbosity as usize)))
        }
        if self.quietness > 0 {
            arguments.push(format!("-{}", "q".repeat(self.quietness as usize)))
        }
        if self.color_choice != ColorChoice::Auto {
            arguments.push(format!(
                "--color {}",
                if self.color_choice != ColorChoice::Always {
                    "always"
                } else {
                    "never"
                }
            ));
        }
        arguments.extend(self.arguments);
        info!(
            "executing command `{}`, with arguments {:?}",
            self.command_name, arguments
        );

        todo!()
    }
}