kegani_cli/commands/
docs.rs1use anyhow::Result;
4use console::{style, Emoji};
5use std::process::Command;
6
7pub fn open_docs(section: &str) -> Result<()> {
9 println!();
10 println!("{} {}", Emoji("📚", ""), style("Opening Kegani Documentation").bold());
11 println!();
12
13 let url = match section {
14 "api" => "https://docs.rs/kegani/latest/kegani/",
15 "guide" => "https://kegani.dev/guide",
16 "crates" => "https://crates.io/crates/kegani",
17 "github" => "https://github.com/kegani/kegani",
18 "examples" => "https://github.com/kegani/kegani/examples",
19 _ => {
20 println!(" {} Unknown section '{}'. Using guide.", style("⚠").yellow(), section);
21 "https://kegani.dev/guide"
22 }
23 };
24
25 println!(" {} {}", style("→").cyan(), style(url).underlined().cyan());
26 println!();
27
28 let open_result: Option<std::process::ExitStatus> =
30 if cfg!(target_os = "macos") {
31 Command::new("open").arg(url).status().ok()
32 } else if cfg!(target_os = "linux") {
33 Command::new("xdg-open").arg(url).status().ok()
34 } else if cfg!(target_os = "windows") {
35 Command::new("start").arg(url).status().ok()
36 } else {
37 None
38 };
39
40 match open_result {
41 Some(status) if status.success() => {
42 println!(" {} {}", style("✓").green(), style("Opened in browser").green());
43 }
44 _ => {
45 println!(" {} Could not open browser automatically.", style("ℹ").dim());
46 println!(" {} Copy this URL manually: {}", style("→").cyan(), url);
47 }
48 }
49
50 Ok(())
51}