diff --git a/src/main.rs b/src/main.rs index a33face..9bb08d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,10 @@ pub struct Cli { /// Generate typescript files #[clap(long, short)] pub typescript: bool, + + /// Overwrite existing component + #[clap(long)] + pub force: bool, } #[derive(Serialize, Deserialize, Debug)] @@ -62,6 +66,8 @@ pub struct Config { pub verbose_output: Option, pub typescript: Option, + + pub force: Option, } #[derive(Debug, Serialize, Deserialize, PartialEq)] @@ -134,10 +140,13 @@ fn main() { let component_name = component_name[0]; // Check if the component already exists - if Path::new(&format!("{resolved_path}/{component_name}")).exists() { - warn_and_exit(&format!( - "A component with name \"{component_name}\" already exists" - )); + if config.force.unwrap_or_default() || args.force { + } else { + if Path::new(&format!("{resolved_path}/{component_name}")).exists() { + warn_and_exit(&format!( + "A component with name \"{component_name}\" already exists" + )); + } } // create missing directories diff --git a/src/utility.rs b/src/utility.rs index 80f1419..ce824b9 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -85,7 +85,7 @@ pub fn write_component_from_template( let content = content.replace("_component", &format!("{}", name_and_extension.0)); if use_template_extension { - extension = get_extension(entry.file_name().to_str().unwrap()); + extension = get_file_extension(entry.file_name().to_str().unwrap()); } if entry.file_name().to_str().unwrap().contains("_component") { @@ -158,6 +158,7 @@ pub fn generate_config() { component_type: Some("functional".to_owned()), typescript: Some(false), verbose_output: Some(false), + force: Some(false), }; fs::write( @@ -167,7 +168,7 @@ pub fn generate_config() { .unwrap(); } -fn get_extension(file_name_with_extension: &str) -> String { +fn get_file_extension(file_name_with_extension: &str) -> String { file_name_with_extension .split(".") .next()