#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CliSpec {
pub bin_name: String,
pub root: CommandSpec,
pub outputs: Vec<OutputSpec>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CommandSpec {
pub name: String,
pub display_name: Option<String>,
pub about: Option<String>,
pub long_about: Option<String>,
pub args: Vec<ArgSpec>,
pub subcommands: Vec<CommandSpec>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ArgSpec {
pub id: String,
pub long: Option<String>,
pub short: Option<char>,
pub help: Option<String>,
pub long_help: Option<String>,
pub kind: ArgKind,
pub required: bool,
pub global: bool,
pub value: ValueSpec,
pub defaults: Vec<String>,
pub possible_values: Vec<EnumValue>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ArgKind {
FlagTrue,
FlagFalse,
Counter,
Option,
Positional,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct ValueSpec {
pub names: Vec<String>,
pub ty: ValueType,
pub arity: ValueArity,
pub hint: Option<String>,
pub repeated: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValueType {
Unknown,
String,
OsString,
Path,
Bool,
Integer,
BigInteger,
Float,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ValueArity {
pub min: usize,
pub max: Option<usize>,
}
impl ValueArity {
#[must_use]
pub const fn exact(count: usize) -> Self {
Self {
min: count,
max: Some(count),
}
}
#[must_use]
pub const fn takes_values(self) -> bool {
self.max.is_none() || matches!(self.max, Some(max) if max > 0)
}
#[must_use]
pub const fn allows_multiple(self) -> bool {
match self.max {
Some(max) => max > 1,
None => true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct EnumValue {
pub name: String,
pub help: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct OutputSpec {
pub command_path: Vec<String>,
pub encoding: OutputEncoding,
pub mode: OutputMode,
pub type_name: String,
pub schema: Option<OutputSchema>,
}
impl OutputSpec {
#[must_use]
pub fn new(
command_path: Vec<String>,
encoding: OutputEncoding,
mode: OutputMode,
type_name: impl Into<String>,
) -> Self {
Self {
command_path,
encoding,
mode,
type_name: type_name.into(),
schema: None,
}
}
#[must_use]
pub fn with_schema(mut self, schema: OutputSchema) -> Self {
self.schema = Some(schema);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum OutputEncoding {
Json,
JsonLines,
Text,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum OutputMode {
Buffered,
Streaming,
Interactive,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum OutputSchema {
JsonSchema(String),
}