Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packer fmt formatter #169

Merged
merged 3 commits into from
Mar 12, 2024
Merged

Add packer fmt formatter #169

merged 3 commits into from
Mar 12, 2024

Conversation

tomeon
Copy link
Contributor

@tomeon tomeon commented Mar 12, 2024

Due to the fact that packer fmt accepts only a single file or directory as an argument, this PR includes a not-particularly-pretty wrapper script that calls out to packer fmt once per included source file, and a not-particularly-robust mechanism for distinguishing included source files from packer fmt options (basically, trying to plop a bare -- between options and source file arguments).

Also includes some updates to the "Adding new formatters" section of the README; would be happy to spin these changes into a separate PR if that's preferable.

Thanks in advance!

tomeon and others added 3 commits March 11, 2024 18:04
that runs `packer fmt` on `*.pkr.hcl` and `*.pkrvars.hcl` files.
to (a) remove mention of the deleted `./bors.toml.sh`, (b) consistently
render file names in monospace, (c) replace `nix develop -c treefmt`
with `nix fmt`, and (d) provide some additional guidance on how to test
the newly-introduced formatter.
Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. Do you mind also contacting upstream so it eventually gets fixed?

@tomeon
Copy link
Contributor Author

tomeon commented Mar 12, 2024

Do you mind also contacting upstream so it eventually gets fixed?

Done: hashicorp/packer#12883.

@zimbatm zimbatm merged commit 35791f7 into numtide:main Mar 12, 2024
231 checks passed
@tomeon tomeon deleted the packer-init branch March 13, 2024 17:43
@dawidd6
Copy link

dawidd6 commented Mar 17, 2024

Isn't this the same as hclfmt though?

@zimbatm
Copy link
Member

zimbatm commented Mar 17, 2024

probably. I would use hclfmt as it follows the treefmt spec. But I haven't used Packer for a while, maybe there is some extra semantic that packer fmt understands?

@tomeon
Copy link
Contributor Author

tomeon commented Mar 17, 2024

[M]aybe there is some extra semantic that packer fmt understands?

Allegedly several of the <hashicorp-tool> fmt subcommands, including packer fmt, have tool-specific behavior, according to Hashicorp employees/contributors here and here. Such that running hclfmt after packer fmt is (or should be) idempotent, but running packer fmt after hclfmt isn't.

@thomaslaich thomaslaich mentioned this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants