Skip to content

Commit

Permalink
feat: support nginxbeautifier
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Oct 26, 2024
1 parent 6a7bf27 commit 4db002c
Show file tree
Hide file tree
Showing 6 changed files with 68 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 nginxbeautifier [`#514`](https://github.com/hougesen/mdsf/pull/514)
- feat: support cabal-fmt [`#513`](https://github.com/hougesen/mdsf/pull/513)
- feat: support bibtex-tidy [`#512`](https://github.com/hougesen/mdsf/pull/512)
- feat: support caddy fmt [`#511`](https://github.com/hougesen/mdsf/pull/511)
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 204 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 205 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -302,6 +302,7 @@ mdsf init
| `misspell` | `misspell -w PATH` |
| `mix:format` | `mix format PATH` |
| `mojo:format` | `mojo format -q PATH` |
| `nginxbeautifier` | `nginxbeautifier PATH` |
| `nickel:format` | `nickel format PATH` |
| `nimpretty` | `nimpretty PATH` |
| `nixfmt` | `nixfmt PATH` |
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub mod mdslw;
pub mod misspell;
pub mod mix_format;
pub mod mojo_format;
pub mod nginxbeautifier;
pub mod nickel_format;
pub mod nimpretty;
pub mod nixfmt;
Expand Down Expand Up @@ -663,6 +664,10 @@ pub enum Tooling {
/// `mojo format -q $PATH`
MojoFormat,

#[serde(rename = "nginxbeautifier")]
/// `nginxbeautifier $PATH`
Nginxbeautifier,

#[serde(rename = "nickel:format")]
/// `nickel format $PATH`
NickelFormat,
Expand Down Expand Up @@ -1146,6 +1151,7 @@ impl Tooling {
Self::Misspell => misspell::run(snippet_path),
Self::MixFormat => mix_format::run(snippet_path),
Self::MojoFormat => mojo_format::run(snippet_path),
Self::Nginxbeautifier => nginxbeautifier::run(snippet_path),
Self::NickelFormat => nickel_format::run(snippet_path),
Self::Nimpretty => nimpretty::run(snippet_path),
Self::Nixfmt => nixfmt::run(snippet_path),
Expand Down Expand Up @@ -1359,6 +1365,7 @@ impl AsRef<str> for Tooling {
Self::Misspell => "misspell",
Self::MixFormat => "mix_format",
Self::MojoFormat => "mojo_format",
Self::Nginxbeautifier => "nginxbeautifier",
Self::NickelFormat => "nickel_format",
Self::Nimpretty => "nimpretty",
Self::Nixfmt => "nixfmt",
Expand Down
38 changes: 38 additions & 0 deletions mdsf/src/tools/nginxbeautifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_nginxbeautifier_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [
CommandType::NodeModules("nginxbeautifier"),
CommandType::Direct("nginxbeautifier"),
CommandType::Npm("nginxbeautifier"),
];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_nginxbeautifier_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_nginxbeautifier {}
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 @@ -628,6 +628,11 @@
"type": "string",
"enum": ["mojo:format"]
},
{
"description": "`nginxbeautifier $PATH`",
"type": "string",
"enum": ["nginxbeautifier"]
},
{
"description": "`nickel format $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/nginxbeautifier/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "nginxbeautifier",
"categories": ["formatter"],
"commands": {
"": ["$PATH"]
},
"description": "Format and beautify nginx config files",
"homepage": "https://github.com/vasilevich/nginxbeautifier",
"languages": ["nginx"],
"name": null,
"npm": "nginxbeautifier",
"php": null,
"tests": []
}

0 comments on commit 4db002c

Please sign in to comment.