Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deployments): add tier confirmation prompt for pricing #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 36 additions & 0 deletions cli/src/command/deployments/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<std::collections::HashMap<_, _>>();

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?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No unit for the price. Is it credit, or $USD?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is rendered as $ wich assumes USD I guess and credits are also USD

&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()?;
Expand Down Expand Up @@ -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,
};

Expand Down
4 changes: 3 additions & 1 deletion cli/src/command/deployments/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions cli/src/command/deployments/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down