Skip to content

Commit

Permalink
feat(init/userstyle): gate comment removal behind explicit `--clear-c…
Browse files Browse the repository at this point in the history
…omments` flag
  • Loading branch information
uncenter committed Jan 16, 2025
1 parent 9a41fdc commit 913a339
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ pub enum Template {
/// URL to the application
#[arg(long, value_parser = valid_url)]
url: Option<String>,

#[arg(long)]
clear_comments: bool,
},
}

Expand Down
9 changes: 6 additions & 3 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub fn userstyle(
icon: Option<String>,
color: Option<String>,
url: Option<String>,
clear_comments: bool,
) -> Result<()> {
let cwd = env::current_dir()?;
if !cwd.join(PathBuf::from("scripts/userstyles.yml")).exists() {
Expand Down Expand Up @@ -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")),
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
}
Expand Down

0 comments on commit 913a339

Please sign in to comment.