From cdab1532e6f6d964788b0fa083762c390838f9a2 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sat, 9 Mar 2024 19:21:51 +0100 Subject: [PATCH] refactor: move schema generator back to bin --- Cargo.toml | 9 +-------- src/bin/init-schema.rs | 18 ------------------ src/cli.rs | 2 ++ src/main.rs | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 26 deletions(-) delete mode 100644 src/bin/init-schema.rs diff --git a/Cargo.toml b/Cargo.toml index 75131109..f55c508c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,10 @@ description = "Format markdown code snippets using your favorite code formatters authors = ["Mads Hougesen "] license = "MIT" repository = "https://github.com/hougesen/mdsf" -keywords = ["markdown", "formatter", "pretty-printing"] +keywords = ["markdown", "formatter", "pretty-printing", "code-formatter"] homepage = "https://github.com/hougesen/mdsf" readme = "README.md" categories = ["development-tools"] -default-run = "mdsf" [dependencies] clap = { version = "4.5.2", features = ["derive"] } @@ -21,9 +20,3 @@ schemars = "0.8.16" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" tempfile = "3.10.1" - -[[bin]] -name = "mdsf" - -[[bin]] -name = "init-schema" diff --git a/src/bin/init-schema.rs b/src/bin/init-schema.rs deleted file mode 100644 index b7bc0bb6..00000000 --- a/src/bin/init-schema.rs +++ /dev/null @@ -1,18 +0,0 @@ -use mdsf::config::MdsfConfig; -use schemars::schema_for; - -fn main() -> std::io::Result<()> { - let mut p = std::env::current_dir()?; - - let package_version = env!("CARGO_PKG_VERSION"); - - p.push(format!("schemas/v{package_version}")); - - std::fs::create_dir_all(&p)?; - - let schema = serde_json::to_string_pretty(&schema_for!(MdsfConfig))?; - - std::fs::write(p.join("mdsf.schema.json"), schema)?; - - Ok(()) -} diff --git a/src/cli.rs b/src/cli.rs index 125057e2..e7b49282 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,6 +13,8 @@ pub enum Commands { Format(FormatCommandArguments), /// Create a new mdsf config Init, + /// Generate json schema + Schema, } /// Run formatters on input files diff --git a/src/main.rs b/src/main.rs index a402b152..a01e3918 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,10 +42,27 @@ fn init_config_command() -> std::io::Result<()> { Ok(()) } +fn generate_schema_command() -> std::io::Result<()> { + let mut p = std::env::current_dir()?; + + let package_version = env!("CARGO_PKG_VERSION"); + + p.push(format!("schemas/v{package_version}")); + + std::fs::create_dir_all(&p)?; + + let schema = serde_json::to_string_pretty(&schemars::schema_for!(MdsfConfig))?; + + std::fs::write(p.join("mdsf.schema.json"), schema)?; + + Ok(()) +} + fn main() { let command_result = match Cli::parse().command { Commands::Format(args) => format_command(args), Commands::Init => init_config_command().map_err(MdsfError::from), + Commands::Schema => generate_schema_command().map_err(MdsfError::from), }; if let Err(error) = command_result {