sindri_cli/commands/
deploy.rs

1use std::collections::HashMap;
2
3use regex::Regex;
4use sindri::{client::SindriClient, CircuitInfo, JobStatus};
5
6use crate::handle_operation_error;
7
8pub fn deploy(
9    client: &SindriClient,
10    project: String,
11    tags: Option<Vec<String>>,
12    meta: Option<Vec<String>>,
13) {
14    println!("{}", console::style("Deploying...").bold());
15
16    // Convert metadata strings into HashMap
17    let meta_rules = Regex::new(r"^[a-zA-Z0-9]+=[a-zA-Z0-9]+$").unwrap();
18    let metadata = meta.map(|pairs| {
19        pairs
20            .into_iter()
21            .filter_map(|pair| {
22                if meta_rules.is_match(&pair) {
23                    let mut parts = pair.splitn(2, '=');
24                    Some((
25                        parts.next()?.to_string(),
26                        parts.next().unwrap_or_default().to_string(),
27                    ))
28                } else {
29                    handle_operation_error(
30                        "Deploy",
31                        &format!("\"{pair}\" is not a valid metadata pair."),
32                    );
33                }
34            })
35            .collect::<HashMap<String, String>>()
36    });
37    println!(
38        "{}",
39        console::style(format!(
40            "  ✓ Valid metadata pairs specified: {}",
41            metadata.as_ref().map_or(0, |t| t.len())
42        ))
43        .cyan()
44    );
45
46    match client.create_circuit_blocking(project, tags, metadata) {
47        Ok(response) => {
48            // Gather circuit identifiers from response
49            let status = *response.status();
50            if status == JobStatus::Ready {
51                let uuid = response.id();
52                let team = response.team_slug();
53                let project_name = response.project_name();
54                let first_tag = response.tags().first().cloned().unwrap_or_default();
55
56                println!(
57                    "{}",
58                    console::style("  ✓ Circuit created successfully!").cyan()
59                );
60                println!(
61                    "\n{}",
62                    console::style("To generate a proof from this deployment, you can use either:")
63                        .bold()
64                );
65                println!("• Circuit UUID: {}", console::style(uuid).cyan());
66                println!(
67                    "• Identifier:  {}",
68                    console::style(format!("{}/{}:{}", team, project_name, first_tag)).cyan()
69                );
70            } else {
71                handle_operation_error("Deploy", &response.error().unwrap_or_default())
72            }
73        }
74        Err(e) => handle_operation_error("Deploy", &e.to_string()),
75    }
76}