diff --git a/Cargo.lock b/Cargo.lock index 72d9182..a88b8f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -364,7 +364,6 @@ dependencies = [ "axum 0.7.5", "bitcode", "chrono", - "clap", "color-eyre", "comrak", "console-subscriber", diff --git a/Cargo.toml b/Cargo.toml index 712e6e8..9858564 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,9 @@ version = "0.1.0" edition = "2021" default-run = "bingus-blog" -[[bin]] -name = "syntect-to-css" -required-features = ["clap"] - [features] default = ["precompression"] tokio-console = ["dep:console-subscriber"] -clap = ["dep:clap"] precompression = ["dep:async-compression"] [profile.release] @@ -27,7 +22,6 @@ async-compression = { version = "0.4.8", optional = true } axum = { version = "0.7.5", features = ["macros"] } bitcode = { version = "0.6.0", features = ["serde"] } chrono = { version = "0.4.37", features = ["serde"] } -clap = { version = "4.5.4", features = ["derive"], optional = true } color-eyre = "0.6.3" comrak = { version = "0.22.0", features = ["syntect"] } console-subscriber = { version = "0.2.0", optional = true } diff --git a/src/bin/syntect-to-css.rs b/src/bin/syntect-to-css.rs deleted file mode 100644 index 3124cbb..0000000 --- a/src/bin/syntect-to-css.rs +++ /dev/null @@ -1,76 +0,0 @@ -use std::fs::File; -use std::io::BufReader; -use std::path::PathBuf; - -use clap::Parser; -use color_eyre::eyre::{self, Context, Ok, OptionExt}; -use syntect::highlighting::{Theme, ThemeSet}; -use syntect::html::{css_for_theme_with_class_style, ClassStyle}; - -#[derive(Parser, Debug)] -#[command(about = "generate CSS from a syntect theme")] -struct Args { - #[command(subcommand)] - command: Command, - #[arg( - short, - long, - help = "prefix for generated classes", - default_value = "syntect-" - )] - prefix: String, - #[arg( - long, - help = "don't add a prefix to generated classes", - default_value_t = false - )] - no_prefix: bool, -} - -#[derive(Parser, Debug)] -enum Command { - #[command(about = "generate CSS from a theme in the default theme set")] - Default { - #[arg(help = "name of theme (no .tmTheme)")] - theme_name: String, - }, - #[command(about = "generate CSS from a .tmTheme file")] - File { - #[arg(help = "path to theme (including .tmTheme)")] - path: PathBuf, - }, -} - -fn main() -> eyre::Result<()> { - let args = Args::parse(); - color_eyre::install()?; - - let theme = match args.command { - Command::Default { theme_name } => { - let ts = ThemeSet::load_defaults(); - ts.themes - .get(&theme_name) - .ok_or_eyre(format!("theme {:?} doesn't exist", theme_name))? - .to_owned() - } - Command::File { path } => { - let mut file = BufReader::new( - File::open(&path).with_context(|| format!("failed to open {:?}", path))?, - ); - ThemeSet::load_from_reader(&mut file).with_context(|| "failed to parse theme")? - } - }; - - let class_style = if args.no_prefix { - ClassStyle::Spaced - } else { - ClassStyle::SpacedPrefixed { - prefix: args.prefix.leak(), - } - }; - - let css = css_for_theme_with_class_style(&theme, class_style) - .with_context(|| "failed to generate css")?; - println!("{css}"); - Ok(()) -}