Skip to content

Commit

Permalink
order of instructions similar to loco-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Nov 10, 2024
1 parent 7fecead commit 8949328
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
29 changes: 17 additions & 12 deletions loco-new/src/wizard.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! This module provides interactive utilities for setting up application configurations
//! based on user input.
//! This module provides interactive utilities for setting up application
//! configurations based on user input.
use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select};
use strum::IntoEnumIterator;

use crate::{
wizard_opts::{self, AssetsOption, BackgroundOption, DBOption},
Error,
};
use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select};
use strum::IntoEnumIterator;

/// Holds the user's configuration selections.
pub struct Selections {
Expand All @@ -32,8 +33,8 @@ impl Selections {
}
}

/// Prompts the user to enter an application name, with optional pre-set name input.
/// Validates the name to ensure compliance with required naming rules.
/// Prompts the user to enter an application name, with optional pre-set name
/// input. Validates the name to ensure compliance with required naming rules.
/// Returns the validated name or an error if validation fails.
///
/// # Errors
Expand All @@ -58,8 +59,9 @@ pub fn app_name(name: Option<String>) -> crate::Result<String> {
}
}

/// Warns the user if the current directory is inside a Git repository and prompts
/// them to confirm whether they wish to proceed. If declined, an error is returned.
/// Warns the user if the current directory is inside a Git repository and
/// prompts them to confirm whether they wish to proceed. If declined, an error
/// is returned.
///
/// # Errors
/// when could not show user selection or user chose not continue
Expand Down Expand Up @@ -150,15 +152,16 @@ pub fn start(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<Selections> {
background: select_background(args)?,
asset: AssetsOption::Clientside,
}),
wizard_opts::Template::Advance => Ok(Selections {
wizard_opts::Template::Advanced => Ok(Selections {
db: select_db(args)?,
background: select_background(args)?,
asset: select_asset(args)?,
}),
}
}

/// Prompts the user to select a database option if none is provided in the arguments.
/// Prompts the user to select a database option if none is provided in the
/// arguments.
fn select_db(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<DBOption> {
let dboption = if let Some(dboption) = args.db.clone() {
dboption
Expand All @@ -171,7 +174,8 @@ fn select_db(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<DBOption> {
Ok(dboption)
}

/// Prompts the user to select a background worker option if none is provided in the arguments.
/// Prompts the user to select a background worker option if none is provided in
/// the arguments.
fn select_background(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<BackgroundOption> {
let bgopt = if let Some(bgopt) = args.bg.clone() {
bgopt
Expand All @@ -184,7 +188,8 @@ fn select_background(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<Backg
Ok(bgopt)
}

/// Prompts the user to select an asset configuration if none is provided in the arguments.
/// Prompts the user to select an asset configuration if none is provided in the
/// arguments.
fn select_asset(args: &wizard_opts::ArgsPlaceholder) -> crate::Result<AssetsOption> {
let assetopt = if let Some(assetopt) = args.assets.clone() {
assetopt
Expand Down
36 changes: 18 additions & 18 deletions loco-new/src/wizard_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use strum::{Display, EnumIter};
)]
pub enum Template {
#[default]
#[strum(to_string = "lightweight-service (minimal, only controllers and views)")]
Lightweight,
#[strum(to_string = "Rest API (with DB and user auth)")]
RestApi,
#[strum(to_string = "Saas App with server side rendering")]
SaasServerSideRendering,
#[strum(to_string = "Saas App with client side rendering")]
SaasClientSideRendering,
#[strum(to_string = "Advance")]
Advance,
#[strum(to_string = "Rest API (with DB and user auth)")]
RestApi,
#[strum(to_string = "lightweight-service (minimal, only controllers and views)")]
Lightweight,
#[strum(to_string = "Advanced")]
Advanced,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
Expand Down Expand Up @@ -101,14 +101,14 @@ impl BackgroundOption {
pub fn user_message(&self) -> Option<String> {
match self {
Self::Queue => Some(format!(
"{}: You've selected `{}` for your background worker configuration (you should have a \
Redis/valkey instance to connect to)",
"workers".underline(),
"queue".yellow()
)),
"{}: You've selected `{}` for your background worker configuration (you should \
have a Redis/valkey instance to connect to)",
"workers".underline(),
"queue".yellow()
)),
Self::Blocking => Some(format!(
"{}: You've selected `{}` for your background worker configuration. Your workers \
configuration will BLOCK REQUESTS until a task is done.",
configuration will BLOCK REQUESTS until a task is done.",
"workers".underline(),
"blocking".yellow()
)),
Expand Down Expand Up @@ -153,12 +153,12 @@ impl AssetsOption {
pub fn user_message(&self) -> Option<String> {
match self {
Self::Clientside => Some(format!(
"{}: You've selected `{}` for your asset serving configuration.\n\nNext step, build \
your frontend:\n $ cd {}\n $ npm install && npm run build\n",
"assets".underline(),
"clientside".yellow(),
"frontend/".yellow()
)),
"{}: You've selected `{}` for your asset serving configuration.\n\nNext step, \
build your frontend:\n $ cd {}\n $ npm install && npm run build\n",
"assets".underline(),
"clientside".yellow(),
"frontend/".yellow()
)),
Self::Serverside | Self::None => None,
}
}
Expand Down

0 comments on commit 8949328

Please sign in to comment.