use crate::commands::{Cli, Result};
use clap::Parser;
use color_print::cprintln;

/// Generate markdown file with jobber usage documentation
#[derive(Parser, Debug)]
pub(crate) struct MarkdownDoc {
    /// File to write markdown documentation into
    #[clap(default_value = "commands.md")]
    path: std::path::PathBuf,
}

impl MarkdownDoc {
    pub(crate) fn run(&self, _: &Cli) -> Result<()> {
        let markdown = clap_markdown::help_markdown::<Cli>();
        std::fs::write(&self.path, markdown)?;
        cprintln!(
            "Successfully wrote documentation into file <s>{}</>",
            self.path.to_string_lossy()
        );
        Ok(())
    }
}
