use crate::{ArgumentInfo, CliSources};
use alux_ext::OperationAlg;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommandDescription {
pub path: Vec<&'static str>,
pub doc: &'static str,
pub argument_names: &'static [&'static str],
pub arguments: Vec<ArgumentInfo>,
pub context: Vec<ArgumentInfo>,
pub conventions: Conventions,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(clippy::struct_excessive_bools)]
pub struct Conventions {
pub options_first: bool,
pub unknown_options_are_operands: bool,
pub double_dash_ends_options: bool,
pub verbatim: bool,
pub numeric_option: Option<&'static str>,
}
impl Default for Conventions {
fn default() -> Self {
Self {
options_first: false,
unknown_options_are_operands: false,
double_dash_ends_options: true,
verbatim: false,
numeric_option: None,
}
}
}
impl CommandDescription {
pub fn of<Operation, Sources>(name: &'static str, sources: &Sources) -> Self
where
Operation: OperationAlg,
Sources: CliSources<Operation::Args>,
{
Self {
path: if name.is_empty() { Vec::new() } else { vec![name] },
doc: Operation::DOC,
argument_names: Operation::ARG_NAMES,
arguments: sources.cli_arguments(Operation::ARG_NAMES),
context: Vec::new(),
conventions: Conventions::default(),
}
}
}