pace_core/commands/
docs.rs

1#[cfg(feature = "clap")]
2use clap::Parser;
3
4use crate::{
5    constants::PACE_DOCS_URL,
6    constants::{PACE_CONFIG_DOCS_URL, PACE_DEV_DOCS_URL},
7    error::{PaceResult, UserMessage},
8};
9
10/// `docs` subcommand options
11#[derive(Debug, Clone)]
12#[cfg_attr(feature = "clap", derive(Parser))]
13#[cfg_attr(
14        feature = "clap", clap(group = clap::ArgGroup::new("documentation").multiple(false)))]
15pub struct DocsCommandOptions {
16    /// Open the development documentation
17    #[cfg_attr(feature = "clap", clap(short, long, group = "documentation"))]
18    dev: bool,
19
20    /// Open the config documentation
21    #[cfg_attr(feature = "clap", clap(short, long, group = "documentation"))]
22    config: bool,
23}
24
25impl DocsCommandOptions {
26    /// Handles the `docs` subcommand
27    ///
28    /// # Errors
29    ///
30    /// Returns an error if the browser could not be opened
31    ///
32    /// # Returns
33    ///
34    /// Returns a `UserMessage` with the information about the opened documentation
35    /// that can be displayed to the user
36    #[tracing::instrument(skip(self))]
37    pub fn handle_docs(&self) -> PaceResult<UserMessage> {
38        // If no flag is set, open the regular documentation
39        let user_string = if !self.dev && !self.config {
40            open::that(PACE_DOCS_URL)?;
41
42            format!("Opening the user documentation at {PACE_DOCS_URL}")
43        } else if self.config {
44            // Open the config documentation
45            open::that(PACE_CONFIG_DOCS_URL)?;
46
47            format!("Opening the configuration documentation at {PACE_CONFIG_DOCS_URL}")
48        } else if self.dev {
49            // Open the development documentation
50            open::that(PACE_DEV_DOCS_URL)?;
51
52            format!("Opening the development documentation at {PACE_DEV_DOCS_URL}")
53        } else {
54            "No documentation to open".to_string()
55        };
56
57        Ok(UserMessage::new(user_string))
58    }
59}