Skip to content

Commit

Permalink
feat: support bibtex-tidy (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 26, 2024
1 parent 3404920 commit 67715da
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`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 |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand All @@ -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` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/bibtex_tidy.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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 {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1237,6 +1243,7 @@ impl AsRef<str> 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",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.2.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
"type": "string",
"enum": ["beautysh"]
},
{
"description": "`bibtex-tidy -m $PATH`",
"type": "string",
"enum": ["bibtex-tidy"]
},
{
"description": "`bicep format $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/bibtex-tidy/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 67715da

Please sign in to comment.