Skip to content

Commit

Permalink
feat: support nginxfmt (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Nov 30, 2024
1 parent b1ef96f commit 5458e8e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.3.1...HEAD)

- feat: support nginxfmt [`#552`](https://github.com/hougesen/mdsf/pull/552)
- build(deps): bump which from 6.0.3 to 7.0.0 [`#551`](https://github.com/hougesen/mdsf/pull/551)
- chore: update file extensions [`#550`](https://github.com/hougesen/mdsf/pull/550)
- build(deps): bump clap_complete from 4.5.37 to 4.5.38 [`#546`](https://github.com/hougesen/mdsf/pull/546)
- build(deps): bump hasnep/setup-roc from 0.2.0 to 0.3.0 [`#549`](https://github.com/hougesen/mdsf/pull/549)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 209 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 210 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -330,6 +330,7 @@ mdsf init
| [mix](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) | Code formatter for Elixir | `formatter` | `elixir` |
| [mojo](https://docs.modular.com/mojo/cli/format) | Formats Mojo source files | `formatter` | `mojo` |
| [nginxbeautifier](https://github.com/vasilevich/nginxbeautifier) | Format and beautify nginx config files | `formatter` | `nginx` |
| [nginxfmt](https://github.com/slomkowski/nginx-config-formatter) | nginx config file formatter/beautifier written in Python with no additional dependencies | `formatter` | `nginx` |
| [nickel](https://nickel-lang.org/) | Better configuration for less | `formatter` | `nickel` |
| [nimpretty](https://github.com/nim-lang/nim) | Code formatter for the Nim programming language | `formatter` | `nim` |
| [nixfmt](https://github.com/serokell/nixfmt) | The official (but not yet stable) formatter for Nix code | `formatter` | `nix` |
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 @@ -117,6 +117,7 @@ pub mod misspell;
pub mod mix_format;
pub mod mojo_format;
pub mod nginxbeautifier;
pub mod nginxfmt;
pub mod nickel_format;
pub mod nimpretty;
pub mod nixfmt;
Expand Down Expand Up @@ -696,6 +697,10 @@ pub enum Tooling {
/// `nginxbeautifier $PATH`
Nginxbeautifier,

#[serde(rename = "nginxfmt")]
/// `nginxfmt $PATH`
Nginxfmt,

#[serde(rename = "nickel:format")]
/// `nickel format $PATH`
NickelFormat,
Expand Down Expand Up @@ -1216,6 +1221,7 @@ impl Tooling {
Self::MixFormat => mix_format::run(snippet_path),
Self::MojoFormat => mojo_format::run(snippet_path),
Self::Nginxbeautifier => nginxbeautifier::run(snippet_path),
Self::Nginxfmt => nginxfmt::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 @@ -1442,6 +1448,7 @@ impl AsRef<str> for Tooling {
Self::MixFormat => "mix_format",
Self::MojoFormat => "mojo_format",
Self::Nginxbeautifier => "nginxbeautifier",
Self::Nginxfmt => "nginxfmt",
Self::NickelFormat => "nickel_format",
Self::Nimpretty => "nimpretty",
Self::Nixfmt => "nixfmt",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/nginxfmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

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

#[inline]
fn set_nginxfmt_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::Direct("nginxfmt")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_nginxfmt_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_nginxfmt {}
5 changes: 5 additions & 0 deletions schemas/v0.3.2-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@
"type": "string",
"enum": ["nginxbeautifier"]
},
{
"description": "`nginxfmt $PATH`",
"type": "string",
"enum": ["nginxfmt"]
},
{
"description": "`nickel format $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/nginxfmt/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "nginxfmt",
"categories": ["formatter"],
"commands": {
"": ["$PATH"]
},
"description": "nginx config file formatter/beautifier written in Python with no additional dependencies",
"homepage": "https://github.com/slomkowski/nginx-config-formatter",
"languages": ["nginx"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 5458e8e

Please sign in to comment.