From 417cedefa63017f33448c46adc2b3f28ccd6760b Mon Sep 17 00:00:00 2001 From: Collins Muriuki Date: Mon, 23 Dec 2024 07:29:16 +0300 Subject: [PATCH 1/3] Fix link type cli opts --- src/cli/link_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/link_type.rs b/src/cli/link_type.rs index 4bf7f0e6..639af40d 100644 --- a/src/cli/link_type.rs +++ b/src/cli/link_type.rs @@ -43,8 +43,8 @@ pub struct LinkType { #[structopt(long)] /// Skips UI generation for this link-type. pub no_ui: bool, - #[structopt(long)] + #[structopt(long)] /// Skips test generation for this link-type. pub no_spec: bool, } From 90d2241d510b4c136063fddc04cd56660a71c28f Mon Sep 17 00:00:00 2001 From: Collins Muriuki Date: Mon, 23 Dec 2024 07:53:58 +0300 Subject: [PATCH 2/3] Validate numeric prefixed inputs --- src/cli/web_app.rs | 4 ++-- src/utils.rs | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/cli/web_app.rs b/src/cli/web_app.rs index ecc68a06..798c6b51 100644 --- a/src/cli/web_app.rs +++ b/src/cli/web_app.rs @@ -24,7 +24,7 @@ use crate::{ zome::scaffold_zome_pair, }, templates::ScaffoldedTemplate, - utils::{check_no_whitespace, input_no_whitespace, input_with_case, input_yes_or_no}, + utils::{input_no_whitespace, input_with_case, input_yes_or_no, validate_input}, }; #[derive(Debug, StructOpt)] @@ -57,7 +57,7 @@ impl WebApp { let current_dir = std::env::current_dir()?; let name = match self.name { Some(n) => { - check_no_whitespace(&n, "app name")?; + validate_input(&n, "app name")?; n } None => input_no_whitespace("App name (no whitespaces):")?, diff --git a/src/utils.rs b/src/utils.rs index 020ee717..e0c78373 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -149,7 +149,7 @@ pub fn input_no_whitespace(prompt: &str) -> ScaffoldResult { .with_prompt(prompt) .interact_text()?; - while let Err(e) = check_no_whitespace(&input, "Input") { + while let Err(e) = validate_input(&input, "Input") { println!("{}", e.to_string().red()); input = Input::with_theme(&ColorfulTheme::default()) .with_prompt(prompt) @@ -167,17 +167,27 @@ pub fn check_case(input: &str, identifier: &str, case: Case) -> ScaffoldResult<( "{identifier} must be {case:?} Case", ))); } + if input.chars().next().map_or(false, char::is_numeric) { + return Err(ScaffoldError::InvalidStringFormat(format!( + "{identifier} must not start with a numeric" + ))); + } Ok(()) } #[inline] -/// Raises an error if input is contains white spaces -pub fn check_no_whitespace(input: &str, identifier: &str) -> ScaffoldResult<()> { +/// Raises an error if input is contains white spaces or starts with a numeric +pub fn validate_input(input: &str, identifier: &str) -> ScaffoldResult<()> { if input.contains(char::is_whitespace) { return Err(ScaffoldError::InvalidStringFormat(format!( "{identifier} must *not* contain whitespaces.", ))); } + if input.chars().next().map_or(false, char::is_numeric) { + return Err(ScaffoldError::InvalidStringFormat(format!( + "{identifier} must not start with a numeric" + ))); + } Ok(()) } From baec4f26398a50baab6db4644ff25148dac5877c Mon Sep 17 00:00:00 2001 From: Collins Muriuki Date: Tue, 24 Dec 2024 21:51:17 +0300 Subject: [PATCH 3/3] Update src/utils.rs Co-authored-by: ThetaSinner --- src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index e0c78373..bb6a00a0 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -169,7 +169,7 @@ pub fn check_case(input: &str, identifier: &str, case: Case) -> ScaffoldResult<( } if input.chars().next().map_or(false, char::is_numeric) { return Err(ScaffoldError::InvalidStringFormat(format!( - "{identifier} must not start with a numeric" + "{identifier} must not start with a number" ))); } Ok(())