diff --git a/CHANGELOG.md b/CHANGELOG.md index abf41fd..2ea137d 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 terragrunt hclfmt [`#505`](https://github.com/hougesen/mdsf/pull/505) - feat: support shellharden [`#504`](https://github.com/hougesen/mdsf/pull/504) - feat: support reorder-python-imports [`#503`](https://github.com/hougesen/mdsf/pull/503) - feat: support reformat-gherkin [`#502`](https://github.com/hougesen/mdsf/pull/502) diff --git a/README.md b/README.md index 6a55192..f9652b2 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 195 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 196 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -358,6 +358,7 @@ mdsf init | `taplo` | `taplo format PATH` | | `templ:fmt` | `templ fmt PATH` | | `terraform:fmt` | `terraform fmt -write=true PATH` | +| `terragrunt:hclfmt` | `terragrunt hclfmt --terragrunt-hclfmt-file PATH` | | `tlint:format` | `tlint format PATH` | | `tofu:fmt` | `tofu fmt -write=true PATH` | | `topiary` | `topiary format PATH` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 6d6c130..f883204 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -168,6 +168,7 @@ pub mod swiftformat; pub mod taplo; pub mod templ_fmt; pub mod terraform_fmt; +pub mod terragrunt_hclfmt; pub mod tlint_format; pub mod tofu_fmt; pub mod topiary; @@ -878,6 +879,10 @@ pub enum Tooling { /// `terraform fmt -write=true $PATH` TerraformFmt, + #[serde(rename = "terragrunt:hclfmt")] + /// `terragrunt hclfmt --terragrunt-hclfmt-file $PATH` + TerragruntHclfmt, + #[serde(rename = "tlint:format")] /// `tlint format $PATH` TlintFormat, @@ -1157,6 +1162,7 @@ impl Tooling { Self::Taplo => taplo::run(snippet_path), Self::TemplFmt => templ_fmt::run(snippet_path), Self::TerraformFmt => terraform_fmt::run(snippet_path), + Self::TerragruntHclfmt => terragrunt_hclfmt::run(snippet_path), Self::TlintFormat => tlint_format::run(snippet_path), Self::TofuFmt => tofu_fmt::run(snippet_path), Self::Topiary => topiary::run(snippet_path), @@ -1361,6 +1367,7 @@ impl AsRef for Tooling { Self::Taplo => "taplo", Self::TemplFmt => "templ_fmt", Self::TerraformFmt => "terraform_fmt", + Self::TerragruntHclfmt => "terragrunt_hclfmt", Self::TlintFormat => "tlint_format", Self::TofuFmt => "tofu_fmt", Self::Topiary => "topiary", diff --git a/mdsf/src/tools/terragrunt_hclfmt.rs b/mdsf/src/tools/terragrunt_hclfmt.rs new file mode 100644 index 0000000..4e87bc9 --- /dev/null +++ b/mdsf/src/tools/terragrunt_hclfmt.rs @@ -0,0 +1,36 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_terragrunt_hclfmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("hclfmt"); + cmd.arg("--terragrunt-hclfmt-file"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("terragrunt")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_terragrunt_hclfmt_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_terragrunt_hclfmt {} diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index a518d3a..195b074 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -908,6 +908,11 @@ "type": "string", "enum": ["terraform:fmt"] }, + { + "description": "`terragrunt hclfmt --terragrunt-hclfmt-file $PATH`", + "type": "string", + "enum": ["terragrunt:hclfmt"] + }, { "description": "`tlint format $PATH`", "type": "string", diff --git a/tools/terragrunt/plugin.json b/tools/terragrunt/plugin.json new file mode 100644 index 0000000..50c3c78 --- /dev/null +++ b/tools/terragrunt/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "terragrunt", + "categories": ["formatter"], + "commands": { + "hclfmt": ["hclfmt", "--terragrunt-hclfmt-file", "$PATH"] + }, + "description": "Recursively find hcl files and rewrite them into a canonical format", + "homepage": "https://terragrunt.gruntwork.io/docs/reference/cli-options/#hclfmt", + "languages": ["hcl"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}