use crate::cli::command_arguments::CommandArguments;
use clap::{CommandFactory, Parser};
use log::debug;
use std::process::exit;
#[derive(Parser)]
#[command(version, about)]
pub struct ArgumentsParser {
#[command(subcommand)]
pub command: Option<CommandArguments>,
}
impl ArgumentsParser {
#[must_use]
pub fn get_or_show_help() -> CommandArguments {
match ArgumentsParser::try_parse() {
Ok(cli) => cli.command.unwrap_or_else(|| {
debug!("No command provided. Showing help documentation:\n");
ArgumentsParser::command()
.print_help()
.expect("Help should always print");
exit(1);
}),
Err(error) => error.exit(),
}
}
#[must_use]
pub fn get() -> Option<CommandArguments> {
match ArgumentsParser::try_parse().ok() {
Some(cli) => cli.command,
None => None,
}
}
}