openlatch-client 0.1.5

The open-source security layer for AI agents — client forwarder
/// `openlatch docs` command handler.
///
/// Opens the OpenLatch documentation in the default browser, with URL fallback for headless environments.
use crate::cli::output::OutputConfig;
use crate::error::OlError;

/// The canonical documentation URL.
const DOCS_URL: &str = "https://docs.openlatch.ai";

/// Run the `openlatch docs` command.
///
/// Tries to open the documentation URL in the default browser.
/// Falls back to printing the URL if the browser cannot be launched (headless).
/// Always prints the URL regardless of browser open success.
pub fn run_docs(output: &OutputConfig) -> Result<(), OlError> {
    // Always print URL (even if browser opens successfully)
    if !output.quiet {
        eprintln!("Documentation: {DOCS_URL}");
    }

    // Try to open in browser
    match open::that(DOCS_URL) {
        Ok(()) => {
            output.print_info("Opening in browser...");
        }
        Err(_) => {
            // Headless or no browser available — URL already printed above
            output.print_info("Could not open browser. Visit the URL above.");
        }
    }

    Ok(())
}