Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

add -check flag to fmt #4020

Merged
merged 4 commits into from
Oct 20, 2022
Merged

Conversation

MattSurabian
Copy link
Contributor

This PR is meant to handle #3817 and add check support to the fmt command. There's not much to it but in local testing with waypoint.hcl files it seemed to perform as expected, though it's kinda funny that the default config is generated needing formatting.

matt$ ./waypoint fmt -h
Usage: waypoint fmt [options] [FILE]

  Rewrite a waypoint.hcl file to a canonical format.

  This only works for HCL-formatted Waypoint configuration files. JSON-formatted
  files do not work and will result in an error.

  If FILE is not specified, then the current directory will be searched
  for a "waypoint.hcl" file. If FILE is "-" then the content will be read
  from stdin.

  This command does not validate the waypoint.hcl configuration. This will
  work for older and newer configuration formats.

Global Options:

  -app=<string>
      App to target. Certain commands require a single app target for Waypoint
      configurations with multiple apps. If you have a single app, then this
      can be ignored. This is aliased as "-a".

  -plain
      Plain output: no colors, no animation. The default is false.

  -project=<string>
      Project to target. This is aliased as "-p".

  -workspace=<string>
      Workspace to operate in. This is aliased as "-w".

Command Options:

  -check
      Check if the input is formatted. Exit status will be 0 if all input is
      properly formatted and non-zero otherwise. The default is false.

  -write
      Overwrite the input file. If this is false, the formatted output will be
      written to STDOUT. This has no effect when formatting from STDIN or when
      using the -check flag. The default is true.

nick-cage:waypoint on 3817-fmt-check 
matt$ ./waypoint init
Do you want help generating a waypoint.hcl file? Type 'yes' to initialize the interactive generator or 'no' to generate a template waypoint.hcl file: no

Generating template file

Initial Waypoint configuration created!
No Waypoint configuration was found in this directory.

A sample configuration has been created in the file "waypoint.hcl". This
file is heavily commented to help you get started.

Once you've setup your initial configuration, run "waypoint init" again to
validate the configuration and initialize your project.


nick-cage:waypoint on 3817-fmt-check 
matt$ ./waypoint fmt -check waypoint.hcl 


nick-cage:waypoint on 3817-fmt-check 
matt$ echo $?
3

nick-cage:waypoint on 3817-fmt-check 
matt$ ./waypoint fmt
waypoint.hcl

nick-cage:waypoint on 3817-fmt-check 
matt$ ./waypoint fmt -check waypoint.hcl 

nick-cage:waypoint on 3817-fmt-check 
matt$ echo $?
0

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Thanks for adding this flag to our fmt command! I've got a small doc string suggestion for you, but otherwise this makes sense!

internal/cli/fmt.go Outdated Show resolved Hide resolved
@MattSurabian
Copy link
Contributor Author

Suggestion makes sense to me, I almost went for that initially but opted for the language in the issue instead. I think this is definitely clearer. 👍

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Looks great to me! Tested it locally and it works.

I went ahead and made a changelog and auto-generated the website for you, however since this PR was opened on your fork, I don't think I have push permissions. If you wanted to cherry-pick my commits then I'd say we're good to merge this one! It's over on this branch: https://github.com/hashicorp/waypoint/compare/4020/check-flag-fmt?expand=1

@MattSurabian
Copy link
Contributor Author

Just rebased main on and then cherry picked your commits. Did em in reverse order so changelog was last but I assume it's getting squashed anyway so prolly doesn't matter. Thanks!

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you for making this contribution! 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add -check flag to waypoint fmt
2 participants