Skip to main content

ironflow_cli/commands/
dashboard.rs

1//! `ironflow-cli dashboard` -- open the web dashboard.
2
3use anyhow::Result;
4use clap::Args;
5use ironflow_sdk::IronflowClient;
6
7/// Arguments for the `dashboard` command.
8#[derive(Debug, Args)]
9pub struct DashboardArgs {
10    /// Print the URL instead of opening it in a browser.
11    #[arg(long)]
12    pub print: bool,
13}
14
15/// Execute the `dashboard` command.
16///
17/// Constructs the dashboard URL from the client's base URL and either opens
18/// it in the default browser or prints it to stdout.
19///
20/// # Errors
21///
22/// Returns an error if the browser cannot be opened.
23pub fn execute(client: &IronflowClient, args: &DashboardArgs) -> Result<()> {
24    let url = client.base_url().to_string();
25
26    if args.print {
27        println!("{url}");
28    } else {
29        println!("Opening {url}");
30        open::that(&url)?;
31    }
32
33    Ok(())
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn dashboard_print_returns_ok() {
42        let client = IronflowClient::new("https://ironflow.example.com", "key");
43        let args = DashboardArgs { print: true };
44        execute(&client, &args).unwrap();
45    }
46}