From 3813b2bc8a32579ec4091381dbd47048d110556b Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sat, 26 Oct 2024 23:59:58 +0200 Subject: [PATCH] feat: support bibtex-tidy --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/bibtex_tidy.rs | 35 +++++++++++++++++++++++++++++++++ mdsf/src/tools/mod.rs | 7 +++++++ schemas/v0.2.7/mdsf.schema.json | 5 +++++ tools/bibtex-tidy/plugin.json | 15 ++++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/bibtex_tidy.rs create mode 100644 tools/bibtex-tidy/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 80e1aba..822977d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD) +- feat: support bibtex-tidy [`#512`](https://github.com/hougesen/mdsf/pull/512) - feat: support caddy fmt [`#511`](https://github.com/hougesen/mdsf/pull/511) - build(deps): bump denoland/setup-deno from 1 to 2 [`#510`](https://github.com/hougesen/mdsf/pull/510) - feat: support protolint [`#509`](https://github.com/hougesen/mdsf/pull/509) diff --git a/README.md b/README.md index cdb996d..2792ed3 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 201 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 202 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -198,6 +198,7 @@ mdsf init | `autopep8` | `autopep8 --in-place PATH` | | `beancount-black` | `bean-black PATH` | | `beautysh` | `beautysh PATH` | +| `bibtex-tidy` | `bibtex-tidy -m PATH` | | `bicep:format` | `bicep format PATH` | | `biome:check` | `biome check --write PATH` | | `biome:format` | `biome format --write PATH` | diff --git a/mdsf/src/tools/bibtex_tidy.rs b/mdsf/src/tools/bibtex_tidy.rs new file mode 100644 index 0000000..ed65d68 --- /dev/null +++ b/mdsf/src/tools/bibtex_tidy.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_bibtex_tidy_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("-m"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("bibtex-tidy")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_bibtex_tidy_args(cmd.build(), file_path); + let execution_result = execute_command(cmd, file_path); + + if index == commands.len() - 1 { + return execution_result; + } + + if let Ok(r) = execution_result { + if !r.0 { + return Ok(r); + } + } + } + + Ok((true, None)) +} + +#[cfg(test)] +mod test_bibtex_tidy {} diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 70f6044..3ed670c 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -8,6 +8,7 @@ pub mod autoflake; pub mod autopep_8; pub mod beancount_black; pub mod beautysh; +pub mod bibtex_tidy; pub mod bicep_format; pub mod biome_check; pub mod biome_format; @@ -244,6 +245,10 @@ pub enum Tooling { /// `beautysh $PATH` Beautysh, + #[serde(rename = "bibtex-tidy")] + /// `bibtex-tidy -m $PATH` + BibtexTidy, + #[serde(rename = "bicep:format")] /// `bicep format $PATH` BicepFormat, @@ -1027,6 +1032,7 @@ impl Tooling { Self::Autopep8 => autopep_8::run(snippet_path), Self::BeancountBlack => beancount_black::run(snippet_path), Self::Beautysh => beautysh::run(snippet_path), + Self::BibtexTidy => bibtex_tidy::run(snippet_path), Self::BicepFormat => bicep_format::run(snippet_path), Self::BiomeCheck => biome_check::run(snippet_path), Self::BiomeFormat => biome_format::run(snippet_path), @@ -1237,6 +1243,7 @@ impl AsRef for Tooling { Self::Autopep8 => "autopep_8", Self::BeancountBlack => "beancount_black", Self::Beautysh => "beautysh", + Self::BibtexTidy => "bibtex_tidy", Self::BicepFormat => "bicep_format", Self::BiomeCheck => "biome_check", Self::BiomeFormat => "biome_format", diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index b016163..7f9d5ec 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -108,6 +108,11 @@ "type": "string", "enum": ["beautysh"] }, + { + "description": "`bibtex-tidy -m $PATH`", + "type": "string", + "enum": ["bibtex-tidy"] + }, { "description": "`bicep format $PATH`", "type": "string", diff --git a/tools/bibtex-tidy/plugin.json b/tools/bibtex-tidy/plugin.json new file mode 100644 index 0000000..4c7bc83 --- /dev/null +++ b/tools/bibtex-tidy/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "bibtex-tidy", + "categories": ["formatter"], + "commands": { + "": ["-m", "$PATH"] + }, + "description": "Cleaner and Formatter for BibTeX files", + "homepage": "https://github.com/FlamingTempura/bibtex-tidy", + "languages": ["bibtex"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}