-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Changes from 1 commit
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 |
---|---|---|
|
@@ -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 | ||
|
@@ -31,6 +31,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, "version for moq") | ||
|
||
flag.Usage = func() { | ||
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`) | ||
|
@@ -42,6 +43,11 @@ func main() { | |
flag.Parse() | ||
flags.args = flag.Args() | ||
|
||
if *printVersion { | ||
fmt.Printf("moq version %s\n", version) | ||
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. Perhaps we should just do 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. 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 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. 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() | ||
|
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.
Should it be
-version
or-v
?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.
Unfortunately, there is not really a standard on how the flag is named to print the version information of a tool. I have seen
-v
,-V
,--version
,-version
andversion
(for tools with a command style arguments API). Therefore we can choose whatever we like.Currently we do not have any single letter flag for
moq
so I suggest to follow the current pattern of named flags and therefore I would keep the longer form of-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.
OK, pretty compelling arguments.