From f9964a46e38a1d1c00fe70325af7058e72c7a53a Mon Sep 17 00:00:00 2001 From: steebchen Date: Mon, 17 Feb 2025 22:43:41 +0700 Subject: [PATCH] feat(deployments): add tier confirmation prompt for pricing Introduce user confirmation for non-basic tiers with pricing details. Adds a `force` flag to skip confirmation and leverages `dialoguer` for interactive prompts. Also integrates `strum_macros` for enum display. --- Cargo.lock | 1 + cli/Cargo.toml | 1 + cli/src/command/deployments/create.rs | 36 +++++++++++++++++++++++++++ cli/src/command/deployments/mod.rs | 4 ++- cli/src/command/deployments/update.rs | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 851ed7a..a9da794 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7827,6 +7827,7 @@ dependencies = [ "serde", "slot 0.33.0", "starknet", + "strum_macros 0.25.3", "thiserror 1.0.69", "tokio", "toml", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 9351127..23efedd 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -32,6 +32,7 @@ starknet.workspace = true toml = "0.8" url.workspace = true update-informer = { version = "1.1", default-features = false, features = ["ureq", "github"] } +strum_macros = "0.25.3" [[bin]] name = "slot" diff --git a/cli/src/command/deployments/create.rs b/cli/src/command/deployments/create.rs index 6b0ae98..1c00ec8 100644 --- a/cli/src/command/deployments/create.rs +++ b/cli/src/command/deployments/create.rs @@ -4,6 +4,8 @@ use std::path::PathBuf; use anyhow::Result; use clap::Args; +use dialoguer::theme::ColorfulTheme; +use dialoguer::Confirm; use katana_cli::file::NodeArgsConfig; use slot::api::Client; use slot::credential::Credentials; @@ -38,10 +40,43 @@ pub struct CreateArgs { #[command(subcommand)] create_commands: CreateServiceCommands, + + #[arg(help = "Force create confirmation", short('f'))] + pub force: bool, } impl CreateArgs { pub async fn run(&self) -> Result<()> { + let tier_pricing = vec![ + (Tier::Basic, "3"), + (Tier::Common, "5"), + (Tier::Epic, "15"), + (Tier::Legendary, "35"), + (Tier::Insane, "50"), + ] + .into_iter() + .collect::>(); + + if self.tier != Tier::Basic { + // billing + if !self.force { + let confirmation = Confirm::with_theme(&ColorfulTheme::default()) + .with_prompt(format!( + "You are creating a `{}` instance, which will cost you around ${} per month (billed daily). Do you want to proceed?", + &self.tier, + tier_pricing.get(&self.tier).unwrap() + )) + .default(false) + .show_default(true) + .wait_for_newline(true) + .interact()?; + + if !confirmation { + return Ok(()); + } + } + } + let service = match &self.create_commands { CreateServiceCommands::Katana(config) => { config.validate()?; @@ -89,6 +124,7 @@ impl CreateArgs { Tier::Basic => DeploymentTier::basic, Tier::Common => DeploymentTier::common, Tier::Epic => DeploymentTier::epic, + Tier::Legendary => DeploymentTier::legendary, Tier::Insane => DeploymentTier::insane, }; diff --git a/cli/src/command/deployments/mod.rs b/cli/src/command/deployments/mod.rs index 96e7443..f22334e 100644 --- a/cli/src/command/deployments/mod.rs +++ b/cli/src/command/deployments/mod.rs @@ -1,6 +1,7 @@ use anyhow::Result; use clap::Subcommand; use colored::*; +use strum_macros::Display; use self::{ accounts::AccountsArgs, create::CreateArgs, delete::DeleteArgs, describe::DescribeArgs, @@ -50,11 +51,12 @@ impl Deployments { } } -#[derive(clap::ValueEnum, Clone, Debug, serde::Serialize)] +#[derive(clap::ValueEnum, Clone, Debug, serde::Serialize, PartialEq, Eq, Hash, Display)] pub enum Tier { Basic, Common, Epic, + Legendary, Insane, } diff --git a/cli/src/command/deployments/update.rs b/cli/src/command/deployments/update.rs index fb05f52..84da2bc 100644 --- a/cli/src/command/deployments/update.rs +++ b/cli/src/command/deployments/update.rs @@ -71,6 +71,7 @@ impl UpdateArgs { Some(Tier::Basic) => Some(DeploymentTier::basic), Some(Tier::Common) => Some(DeploymentTier::common), Some(Tier::Epic) => Some(DeploymentTier::epic), + Some(Tier::Legendary) => Some(DeploymentTier::legendary), Some(Tier::Insane) => Some(DeploymentTier::insane), };