diff --git a/CHANGELOG.md b/CHANGELOG.md index 6381ab0..fbad5a6 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 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) diff --git a/README.md b/README.md index ab8c1d8..0679808 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`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 | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -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` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 8740595..a47858f 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -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; @@ -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, @@ -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), @@ -1359,6 +1365,7 @@ impl AsRef 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", diff --git a/mdsf/src/tools/nginxbeautifier.rs b/mdsf/src/tools/nginxbeautifier.rs new file mode 100644 index 0000000..97effed --- /dev/null +++ b/mdsf/src/tools/nginxbeautifier.rs @@ -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), 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 {} diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index 1db533d..31d8fc1 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -628,6 +628,11 @@ "type": "string", "enum": ["mojo:format"] }, + { + "description": "`nginxbeautifier $PATH`", + "type": "string", + "enum": ["nginxbeautifier"] + }, { "description": "`nickel format $PATH`", "type": "string", diff --git a/tools/nginxbeautifier/plugin.json b/tools/nginxbeautifier/plugin.json new file mode 100644 index 0000000..f2967b3 --- /dev/null +++ b/tools/nginxbeautifier/plugin.json @@ -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": [] +}