use std::fmt;
use camino::Utf8PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ManSection(u8);
impl ManSection {
pub fn new(value: u8) -> Result<Self, InvalidManSection> {
if (1..=8).contains(&value) {
Ok(Self(value))
} else {
Err(InvalidManSection(value))
}
}
#[must_use]
pub const fn as_u8(self) -> u8 {
self.0
}
}
impl Default for ManSection {
fn default() -> Self {
Self(1)
}
}
impl fmt::Display for ManSection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InvalidManSection(pub u8);
impl fmt::Display for InvalidManSection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"invalid man section {}: must be between 1 and 8 inclusive",
self.0
)
}
}
impl std::error::Error for InvalidManSection {}
#[derive(Debug, Clone)]
pub struct RoffConfig {
pub out_dir: Utf8PathBuf,
pub section: ManSection,
pub date: Option<String>,
pub should_split_subcommands: bool,
pub source: Option<String>,
pub manual: Option<String>,
}
impl Default for RoffConfig {
fn default() -> Self {
Self {
out_dir: Utf8PathBuf::from("man"),
section: ManSection::default(),
date: None,
should_split_subcommands: false,
source: None,
manual: None,
}
}
}
#[derive(Debug, Default)]
pub struct RoffOutput {
pub files: Vec<Utf8PathBuf>,
}
impl RoffOutput {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn add_file(&mut self, path: Utf8PathBuf) {
self.files.push(path);
}
}