From 913a3391eb3f8930aa058d4c3db9ee2ee738e4ee Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Thu, 16 Jan 2025 07:41:54 -0500 Subject: [PATCH] feat(init/userstyle): gate comment removal behind explicit `--clear-comments` flag --- src/cli.rs | 3 +++ src/init.rs | 9 ++++++--- src/main.rs | 11 ++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index b80b9b6..c94795b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -98,6 +98,9 @@ pub enum Template { /// URL to the application #[arg(long, value_parser = valid_url)] url: Option, + + #[arg(long)] + clear_comments: bool, }, } diff --git a/src/init.rs b/src/init.rs index b775e66..40a84e7 100644 --- a/src/init.rs +++ b/src/init.rs @@ -124,6 +124,7 @@ pub fn userstyle( icon: Option, color: Option, url: Option, + clear_comments: bool, ) -> Result<()> { let cwd = env::current_dir()?; if !cwd.join(PathBuf::from("scripts/userstyles.yml")).exists() { @@ -203,9 +204,11 @@ pub fn userstyle( .expect("App link should be a valid URL"), ); - let comment_re = - Regex::new(r"(?m)^ +\/\*(?:(?!\*\/|==UserStyle==|deno-fmt-ignore)[\s\S])*?\*\/\n")?; - template = comment_re.replace_all(&template, "").to_string(); + if clear_comments { + let comment_re = + Regex::new(r"(?m)^ +\/\*(?:(?!\*\/|==UserStyle==|deno-fmt-ignore)[\s\S])*?\*\/\n")?; + template = comment_re.replace_all(&template, "").to_string(); + } fs::write( target.join(PathBuf::from("catppuccin.user.less")), diff --git a/src/main.rs b/src/main.rs index f129f46..102be3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,16 @@ fn main() -> Result<()> { icon, color, url, - } => init::userstyle(&mut cache, name, categories, icon, color, url)?, + clear_comments, + } => init::userstyle( + &mut cache, + name, + categories, + icon, + color, + url, + clear_comments, + )?, }, Commands::Whiskerify { input, output } => whiskerify::handle(input, output)?, }