Skip to content

Commit

Permalink
feat: support reformat-gherkin (#502)
Browse files Browse the repository at this point in the history
* feat: support reformat-gherkin

* chore: updated generated code

---------

Co-authored-by: hougesen <hougesen@users.noreply.github.com>
  • Loading branch information
hougesen and hougesen authored Oct 26, 2024
1 parent 1aa1d54 commit 1f42404
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Generated by [`auto-changelog`](/~https://github.com/CookPete/auto-changelog).

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

- deps(clap): upgrade to v4.5.20 [`#501`](/~https://github.com/hougesen/mdsf/pull/501)
- feat: support reformat-gherkin [`#502`](/~https://github.com/hougesen/mdsf/pull/502)
- deps(clap): upgrade to 4.5.20 [`#501`](/~https://github.com/hougesen/mdsf/pull/501)
- deps(clap_complete): 4.5.35 [`#500`](/~https://github.com/hougesen/mdsf/pull/500)
- deps(once_cell): bump to 1.20.2 [`#499`](/~https://github.com/hougesen/mdsf/pull/499)
- deps(regex): bump to 1.11.1 [`#498`](/~https://github.com/hougesen/mdsf/pull/498)
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 192 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 193 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ---------------------- | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -322,6 +322,7 @@ mdsf init
| `qmlfmt` | `qmlfmt -w PATH` |
| `raco:fmt` | `raco fmt -i PATH` |
| `refmt` | `refmt --in-place PATH` |
| `reformat-gherkin` | `reformat-gherkin PATH` |
| `rescript:format` | `rescript format PATH` |
| `roc:format` | `roc format PATH` |
| `rstfmt` | `rstfmt 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 @@ -132,6 +132,7 @@ pub mod pyink;
pub mod qmlfmt;
pub mod raco_fmt;
pub mod refmt;
pub mod reformat_gherkin;
pub mod rescript_format;
pub mod roc_format;
pub mod rstfmt;
Expand Down Expand Up @@ -731,6 +732,10 @@ pub enum Tooling {
/// `refmt --in-place $PATH`
Refmt,

#[serde(rename = "reformat-gherkin")]
/// `reformat-gherkin $PATH`
ReformatGherkin,

#[serde(rename = "rescript:format")]
/// `rescript format $PATH`
RescriptFormat,
Expand Down Expand Up @@ -1106,6 +1111,7 @@ impl Tooling {
Self::Qmlfmt => qmlfmt::run(snippet_path),
Self::RacoFmt => raco_fmt::run(snippet_path),
Self::Refmt => refmt::run(snippet_path),
Self::ReformatGherkin => reformat_gherkin::run(snippet_path),
Self::RescriptFormat => rescript_format::run(snippet_path),
Self::RocFormat => roc_format::run(snippet_path),
Self::Rstfmt => rstfmt::run(snippet_path),
Expand Down Expand Up @@ -1307,6 +1313,7 @@ impl AsRef<str> for Tooling {
Self::Qmlfmt => "qmlfmt",
Self::RacoFmt => "raco_fmt",
Self::Refmt => "refmt",
Self::ReformatGherkin => "reformat_gherkin",
Self::RescriptFormat => "rescript_format",
Self::RocFormat => "roc_format",
Self::Rstfmt => "rstfmt",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/reformat_gherkin.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_reformat_gherkin_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("reformat-gherkin")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_reformat_gherkin_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_reformat_gherkin {}
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 @@ -728,6 +728,11 @@
"type": "string",
"enum": ["refmt"]
},
{
"description": "`reformat-gherkin $PATH`",
"type": "string",
"enum": ["reformat-gherkin"]
},
{
"description": "`rescript format $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/reformat-gherkin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "reformat-gherkin",
"categories": ["formatter"],
"commands": {
"": ["$PATH"]
},
"description": "Reformat-gherkin automatically formats Gherkin files",
"homepage": "/~https://github.com/ducminh-phan/reformat-gherkin",
"languages": ["gherkin"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 1f42404

Please sign in to comment.