-
Notifications
You must be signed in to change notification settings - Fork 37
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
Changes from 3 commits
33c2693
c5876f3
9e5e506
b336508
f616842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,13 +16,17 @@ package main | |||||
|
||||||
import ( | ||||||
"flag" | ||||||
"fmt" | ||||||
"log" | ||||||
"os" | ||||||
|
||||||
"github.com/google/yamlfmt" | ||||||
"github.com/google/yamlfmt/command" | ||||||
"github.com/google/yamlfmt/formatters/basic" | ||||||
) | ||||||
|
||||||
var version string = "0.10.0" | ||||||
|
||||||
func main() { | ||||||
if err := run(); err != nil { | ||||||
log.Fatal(err) | ||||||
|
@@ -34,6 +38,15 @@ func run() error { | |||||
configureHelp() | ||||||
flag.Parse() | ||||||
|
||||||
if *flagVersion { | ||||||
_, err := fmt.Printf("%s\n", version) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
os.Exit(0) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can just
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 😄 |
||||||
} | ||||||
|
||||||
c := &command.Command{ | ||||||
Operation: getOperationFromFlag(), | ||||||
Registry: getFullRegistry(), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,14 @@ All flags must be specified **before** any path arguments. | |
|
||
These flags adjust the command's mode of operation. All of these flags are booleans. | ||
|
||
| Name | Flag | Example | Description | | ||
|:-----------|:---------|:---------------------------|:------------| | ||
| Help | `-help` | `yamlfmt -help` | Print the command usage information. | | ||
| 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. | | ||
| Name | Flag | Example | Description | | ||
| :------------ | :--------- | :-------------------------- | :-------------------------------------------------------- | | ||
| Help | `-help` | `yamlfmt -help` | Print the command usage information. | | ||
| Print Version | `-version` | `yamlfmt -version` | Print the yamlfmt version. | | ||
| 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, didn't notice this |
||
|
||
### Configuration Flags | ||
|
||
|
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 👍
f616842