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

refactor: improve ux #235

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from 2 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
27 changes: 11 additions & 16 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// SPDX-License-Identifier: GPL-3.0

use crate::style::{style, Theme};
use crate::cli::{traits::Cli as _, Cli};
use crate::style::style;
use anyhow::Result;
use clap::{
builder::{PossibleValue, PossibleValuesParser, TypedValueParser},
Args,
};
use std::{fs, path::Path, str::FromStr};

use cliclack::{
clear_screen, confirm, input, intro,
clear_screen, confirm, input,
log::{self, success, warning},
outro, outro_cancel, set_theme,
outro, outro_cancel,
};
use pop_common::{Git, GitHub, Release};
use pop_parachains::{
instantiate_template_dir, is_initial_endowment_valid, Config, Provider, Template,
};
use std::{fs, path::Path, str::FromStr, thread::sleep, time::Duration};
use strum::VariantArray;

const DEFAULT_INITIAL_ENDOWMENT: &str = "1u64 << 60";
Expand Down Expand Up @@ -60,9 +60,6 @@ pub struct NewParachainCommand {
impl NewParachainCommand {
/// Executes the command.
pub(crate) async fn execute(self) -> Result<Template> {
clear_screen()?;
set_theme(Theme);

let parachain_config = if self.name.is_none() {
// If user doesn't select the name guide them to generate a parachain.
guide_user_to_generate_parachain().await?
Expand Down Expand Up @@ -90,13 +87,14 @@ impl NewParachainCommand {

let tag_version = parachain_config.release_tag.clone();

clear_screen()?;
generate_parachain_from_template(name, provider, &template, tag_version, config)?;
Ok(template)
}
}

async fn guide_user_to_generate_parachain() -> Result<NewParachainCommand> {
intro(format!("{}: Generate a parachain", style(" Pop CLI ").black().on_magenta()))?;
Cli.intro("Generate a parachain")?;

let mut prompt = cliclack::select("Select a template provider: ".to_string());
for (i, provider) in Provider::providers().iter().enumerate() {
Expand Down Expand Up @@ -133,8 +131,6 @@ async fn guide_user_to_generate_parachain() -> Result<NewParachainCommand> {
customizable_options = prompt_customizable_options()?;
}

clear_screen()?;

Ok(NewParachainCommand {
name: Some(name),
provider: Some(provider.clone()),
Expand All @@ -153,10 +149,8 @@ fn generate_parachain_from_template(
tag_version: Option<String>,
config: Config,
) -> Result<()> {
intro(format!(
"{}: Generating \"{}\" using {} from {}!",
style(" Pop CLI ").black().on_magenta(),
name_template,
Cli.intro(format!(
"Generating \"{name_template}\" using {} from {}!",
template.name(),
provider.name()
))?;
Expand Down Expand Up @@ -242,6 +236,7 @@ fn get_customization_value(
&& (symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
{
log::warning("Customization options are not available for this template")?;
sleep(Duration::from_secs(3))
}
return Ok(Config {
symbol: symbol.clone().expect("default values"),
Expand Down Expand Up @@ -356,7 +351,7 @@ fn prompt_customizable_options() -> Result<Config> {
.interact()?;
if !is_initial_endowment_valid(&initial_endowment) {
outro_cancel("⚠️ The specified initial endowment is not valid")?;
//Prompt the user if want to use the one by default
// Prompt the user if they want to use the one by default
if !confirm(format!("📦 Would you like to use the default {}?", DEFAULT_INITIAL_ENDOWMENT))
.initial_value(true)
.interact()?
Expand Down
Loading