Skip to content

Commit

Permalink
refactor: move schema generator back to bin
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Mar 9, 2024
1 parent 3d7e3ce commit cdab153
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
9 changes: 1 addition & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ description = "Format markdown code snippets using your favorite code formatters
authors = ["Mads Hougesen <[email protected]>"]
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"] }
Expand All @@ -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"
18 changes: 0 additions & 18 deletions src/bin/init-schema.rs

This file was deleted.

2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum Commands {
Format(FormatCommandArguments),
/// Create a new mdsf config
Init,
/// Generate json schema
Schema,
}

/// Run formatters on input files
Expand Down
17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cdab153

Please sign in to comment.