-
Notifications
You must be signed in to change notification settings - Fork 50
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
feat: add flag to print version #117
Conversation
| Dry Run | `-dry` | `yamlfmt -dry .` | Use [Dry Run](#dry-run) mode | | ||
| Lint | `-lint` | `yamlfmt -lint .` | Use [Lint](#lint) mode | | ||
| Quiet Mode | `-quiet` | `yamlfmt -dry -quiet .` | Use quiet mode. Only has effect in Dry Run or Lint modes. | | ||
| Read Stdin | `-in` | `cat x.yaml \| yamlfmt -in` | Read input from stdin and output result to stdout. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line includes fix of #119
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, didn't notice this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! I have needed this for a while but haven't gotten to it. Eventually I will change this to use ldflags
in the build but until then this is a good stopgap.
I think instead of printing the version as an operation, it would be better if the version flag was simply detected immediately after the flags are parsed in main.go
, at which point it will print out the version. It saves a lot of extra work that the program doesn't need to do if all it's doing is printing out the version. Would you be able to make that change?
| Dry Run | `-dry` | `yamlfmt -dry .` | Use [Dry Run](#dry-run) mode | | ||
| Lint | `-lint` | `yamlfmt -lint .` | Use [Lint](#lint) mode | | ||
| Quiet Mode | `-quiet` | `yamlfmt -dry -quiet .` | Use quiet mode. Only has effect in Dry Run or Lint modes. | | ||
| Read Stdin | `-in` | `cat x.yaml \| yamlfmt -in` | Read input from stdin and output result to stdout. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, didn't notice this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this change, given version flag ignores other flags except help and immediately exit with the version displayed. Is this correct understanding?
Yes that's right! Just a couple small comments there then I think this will be good to go.
cmd/yamlfmt/main.go
Outdated
return err | ||
} | ||
|
||
os.Exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just return nil
here; it exits the program the same way.
os.Exit(0) | |
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'm learning golang again from this project... 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you making the effort to contribute in something that isn't your main language! Means a lot 😄
cmd/yamlfmt/main.go
Outdated
@@ -34,6 +38,15 @@ func run() error { | |||
configureHelp() | |||
flag.Parse() | |||
|
|||
if *flagVersion { | |||
_, err := fmt.Printf("%s\n", version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention in this repo I'm not too worried about errors from fmt.Printf
, so just doing the print here is fine.
I think this can also be simplified to fmt.Println(version)
if I'm not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes simple code 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR and for working with me in the review!
Thank you for your polite review! 🙏 |
When I addressed to create asdf plugin, the way to ensure the version of the binary is not found.
This feature always helps me. So I added a simple flag to print the version.
https://github.com/kachick/asdf-yamlfmt
asdf-vm/asdf-plugins#829