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

Print version with -version flag #138

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// version is the command version, injected at build time.
var version string
var version string = "dev"

type userFlags struct {
outFile string
Expand All @@ -32,6 +32,7 @@ func main() {
flag.StringVar(&flags.formatter, "fmt", "", "go pretty-printer: gofmt, goimports or noop (default gofmt)")
flag.BoolVar(&flags.stubImpl, "stub", false,
"return zero values when no mock implementation is provided, do not panic")
printVersion := flag.Bool("version", false, "show the version for moq")
flag.BoolVar(&flags.skipEnsure, "skip-ensure", false,
"suppress mock implementation check, avoid import cycle if mocks generated outside of the tested package")

Expand All @@ -45,6 +46,11 @@ func main() {
flag.Parse()
flags.args = flag.Args()

if *printVersion {
fmt.Printf("moq version %s\n", version)
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps we should just do fmt.Println(version) - allows for programmatic use too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell, it is pretty standard for a tool to print not only its version but also its name. I quickly tried with docker, kubectl, terraform and some other tools and all of them provide the name as well. The same holds true also for the go command it self. Therefore I am in favor of keeping the name in there.
That being said, if you insist on having only the version printed, I will update the PR of course.

Copy link
Owner

Choose a reason for hiding this comment

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

OK then - no need to be different for the sake of it.

os.Exit(0)
}

if err := run(flags); err != nil {
fmt.Fprintln(os.Stderr, err)
flag.Usage()
Expand Down