Skip to main content

openlatch_client/cli/commands/
docs.rs

1/// `openlatch docs` command handler.
2///
3/// Opens the OpenLatch documentation in the default browser, with URL fallback for headless environments.
4use crate::cli::output::OutputConfig;
5use crate::error::OlError;
6
7/// The canonical documentation URL.
8const DOCS_URL: &str = "https://docs.openlatch.ai";
9
10/// Run the `openlatch docs` command.
11///
12/// Tries to open the documentation URL in the default browser.
13/// Falls back to printing the URL if the browser cannot be launched (headless).
14/// Always prints the URL regardless of browser open success.
15pub fn run_docs(output: &OutputConfig) -> Result<(), OlError> {
16    // Always print URL (even if browser opens successfully)
17    if !output.quiet {
18        eprintln!("Documentation: {DOCS_URL}");
19    }
20
21    // Try to open in browser
22    match open::that(DOCS_URL) {
23        Ok(()) => {
24            output.print_info("Opening in browser...");
25        }
26        Err(_) => {
27            // Headless or no browser available — URL already printed above
28            output.print_info("Could not open browser. Visit the URL above.");
29        }
30    }
31
32    Ok(())
33}