omni/commands/
scale.rs

1use crate::models::ComponentStatus;
2use crate::ui::PremiumUI;
3use anyhow::Result;
4use console::style;
5use dialoguer::{Input, Select};
6use std::{thread, time::Duration};
7use tabled::Table;
8
9impl PremiumUI {
10    pub async fn scale_interactive(&self) -> Result<()> {
11        let components = vec!["Web Frontend", "API Backend", "Database"];
12        let component = Select::with_theme(&self.theme)
13            .with_prompt("Select component to scale")
14            .items(&components)
15            .interact()?;
16
17        let replicas: u32 = Input::with_theme(&self.theme)
18            .with_prompt("Enter number of replicas")
19            .validate_with(|input: &String| -> Result<(), &str> {
20                match input.parse::<u32>() {
21                    Ok(n) if n > 0 && n <= 10 => Ok(()),
22                    _ => Err("Please enter a number between 1 and 10"),
23                }
24            })
25            .interact_text()?
26            .parse()?;
27
28        let mut spinner = self.create_spinner("Scaling component...");
29        thread::sleep(Duration::from_secs(2));
30        spinner.stop_with_message("✓ Scaling completed successfully!".to_string());
31
32        println!("\n{}", style("📊 Updated Component Status").cyan().bold());
33        let status = Table::new(vec![ComponentStatus {
34            name: components[component].into(),
35            status: "Running".into(),
36            replicas: format!("{}/{}", replicas, replicas),
37            cpu: format!("{}m", replicas * 150),
38            memory: format!("{}Mi", replicas * 256),
39        }])
40        .to_string();
41        println!("{}", status);
42
43        Ok(())
44    }
45}