rustic_rs/commands/
docs.rs

1//! `docs` subcommand
2
3use abscissa_core::{status_err, Application, Command, Runnable, Shutdown};
4use anyhow::Result;
5use clap::Subcommand;
6
7use crate::{
8    application::constants::{RUSTIC_CONFIG_DOCS_URL, RUSTIC_DEV_DOCS_URL, RUSTIC_DOCS_URL},
9    RUSTIC_APP,
10};
11
12#[derive(Command, Debug, Clone, Copy, Default, Subcommand, Runnable)]
13enum DocsTypeSubcommand {
14    #[default]
15    /// Show the user documentation
16    User,
17    /// Show the development documentation
18    Dev,
19    /// Show the configuration documentation
20    Config,
21}
22
23/// Opens the documentation in the default browser.
24#[derive(Clone, Command, Default, Debug, clap::Parser)]
25pub struct DocsCmd {
26    #[clap(subcommand)]
27    cmd: Option<DocsTypeSubcommand>,
28}
29
30impl Runnable for DocsCmd {
31    fn run(&self) {
32        if let Err(err) = self.inner_run() {
33            status_err!("{}", err);
34            RUSTIC_APP.shutdown(Shutdown::Crash);
35        };
36    }
37}
38
39impl DocsCmd {
40    fn inner_run(&self) -> Result<()> {
41        let user_string = match self.cmd {
42            // Default to user docs if no subcommand is provided
43            Some(DocsTypeSubcommand::User) | None => {
44                open::that(RUSTIC_DOCS_URL)?;
45                format!("Opening the user documentation at {RUSTIC_DOCS_URL}")
46            }
47            Some(DocsTypeSubcommand::Dev) => {
48                open::that(RUSTIC_DEV_DOCS_URL)?;
49                format!("Opening the development documentation at {RUSTIC_DEV_DOCS_URL}")
50            }
51            Some(DocsTypeSubcommand::Config) => {
52                open::that(RUSTIC_CONFIG_DOCS_URL)?;
53                format!("Opening the configuration documentation at {RUSTIC_CONFIG_DOCS_URL}")
54            }
55        };
56
57        println!("{user_string}");
58
59        Ok(())
60    }
61}