Skip to content

Commit

Permalink
feat: support dockfmt (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 27, 2024
1 parent 6ae1b1c commit 1333f66
Show file tree
Hide file tree
Showing 6 changed files with 66 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 dockfmt [`#523`](https://github.com/hougesen/mdsf/pull/523)
- feat: support json5format [`#522`](https://github.com/hougesen/mdsf/pull/522)
- feat: support kdoc-formatter [`#521`](https://github.com/hougesen/mdsf/pull/521)
- feat: support djade [`#520`](https://github.com/hougesen/mdsf/pull/520)
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 213 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 214 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -240,6 +240,7 @@ mdsf init
| `djade` | `djade PATH` |
| `djlint` | `djlint PATH --reformat` |
| `docformatter` | `docformatter --in-place PATH` |
| `dockfmt` | `dockfmt fmt -w PATH` |
| `docstrfmt` | `docstrfmt PATH` |
| `doctoc` | `doctoc PATH` |
| `dotenv-linter:fix` | `dotenv-linter fix PATH` |
Expand Down
36 changes: 36 additions & 0 deletions mdsf/src/tools/dockfmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::process::Command;

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

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

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_dockfmt_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_dockfmt {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub mod dhall;
pub mod djade;
pub mod djlint;
pub mod docformatter;
pub mod dockfmt;
pub mod docstrfmt;
pub mod doctoc;
pub mod dotenv_linter_fix;
Expand Down Expand Up @@ -424,6 +425,10 @@ pub enum Tooling {
/// `docformatter --in-place $PATH`
Docformatter,

#[serde(rename = "dockfmt")]
/// `dockfmt fmt -w $PATH`
Dockfmt,

#[serde(rename = "docstrfmt")]
/// `docstrfmt $PATH`
Docstrfmt,
Expand Down Expand Up @@ -1129,6 +1134,7 @@ impl Tooling {
Self::Djade => djade::run(snippet_path),
Self::Djlint => djlint::run(snippet_path),
Self::Docformatter => docformatter::run(snippet_path),
Self::Dockfmt => dockfmt::run(snippet_path),
Self::Docstrfmt => docstrfmt::run(snippet_path),
Self::Doctoc => doctoc::run(snippet_path),
Self::DotenvLinterFix => dotenv_linter_fix::run(snippet_path),
Expand Down Expand Up @@ -1351,6 +1357,7 @@ impl AsRef<str> for Tooling {
Self::Djade => "djade",
Self::Djlint => "djlint",
Self::Docformatter => "docformatter",
Self::Dockfmt => "dockfmt",
Self::Docstrfmt => "docstrfmt",
Self::Doctoc => "doctoc",
Self::DotenvLinterFix => "dotenv_linter_fix",
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 @@ -318,6 +318,11 @@
"type": "string",
"enum": ["docformatter"]
},
{
"description": "`dockfmt fmt -w $PATH`",
"type": "string",
"enum": ["dockfmt"]
},
{
"description": "`docstrfmt $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/dockfmt/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "dockfmt",
"categories": ["formatter"],
"commands": {
"": ["fmt", "-w", "$PATH"]
},
"description": "Dockerfile format and parser. Like `gofmt` but for Dockerfiles",
"homepage": "https://github.com/jessfraz/dockfmt",
"languages": ["docker"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 1333f66

Please sign in to comment.