Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit f165686

Browse files
minicutscodyoss
authored andcommittedJan 20, 2020
Add Mockgen Version Flag (#362)
Add -version flag that shows a version provided by Go modules. This strategy works well for module aware invocations of `go get` and `go run` (which means using GO111MODULE=on). If we ever plan to distribute built binaries, it is necessary to amend the strategy with build flags. GOPATH mode versioning is unsupported.
1 parent e00cb15 commit f165686

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed
 

Diff for: ‎README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ contexts too.
88
Installation
99
------------
1010

11-
Once you have [installed Go][golang-install], install the `mockgen` tool:
11+
Once you have [installed Go][golang-install], install the `mockgen` tool.
12+
13+
To get the latest released version use:
1214

1315
```bash
14-
go get github.com/golang/mock/mockgen
16+
GO111MODULE=on go get github.com/golang/mock/mockgen@latest
1517
```
1618

17-
_Note: It is recommended to have `GO111MODULE=on` to ensure the correct
18-
dependencies are used._
19+
If you use `mockgen` in your CI pipeline, it may be more appropriate to fixate
20+
on a specific mockgen version.
21+
1922

2023
Documentation
2124
-------------

Diff for: ‎mockgen/mockgen.go

+6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ var (
5353
copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header")
5454

5555
debugParser = flag.Bool("debug_parser", false, "Print out parser results only.")
56+
version = flag.Bool("version", false, "Print version.")
5657
)
5758

5859
func main() {
5960
flag.Usage = usage
6061
flag.Parse()
6162

63+
if *version {
64+
printVersion()
65+
return
66+
}
67+
6268
var pkg *model.Package
6369
var err error
6470
if *source != "" {

Diff for: ‎mockgen/version.1.11.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// +build !go1.12
16+
17+
package main
18+
19+
import (
20+
"log"
21+
)
22+
23+
func printVersion() {
24+
log.Printf("No version information is available for Mockgen compiled with " +
25+
"version 1.11")
26+
}

Diff for: ‎mockgen/version.1.12.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
// +build go1.12
17+
18+
package main
19+
20+
import (
21+
"fmt"
22+
"log"
23+
"runtime/debug"
24+
)
25+
26+
func printVersion() {
27+
if bi, exists := debug.ReadBuildInfo(); exists {
28+
fmt.Println(bi.Main.Version)
29+
} else {
30+
log.Printf("No version information found. Make sure to use " +
31+
"GO111MODULE=on when running 'go get' in order to use specific " +
32+
"version of the binary.")
33+
}
34+
35+
}

0 commit comments

Comments
 (0)
This repository has been archived.