aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-05-18 13:16:49 +0200
committerTeddy Wing2023-05-18 13:16:49 +0200
commit4859ae4083e5035cc75527423fe5be69a1201b64 (patch)
tree76c80d5dc84d54ad2a3c2fe70a8efb23d87f0d40
parent3fb25b9de7f5673fe2af04606c7b35bb53f1f2bf (diff)
downloadgocapturedrefrace-4859ae4083e5035cc75527423fe5be69a1201b64.tar.bz2
gocapturedrefrace/main: Add version command line argument
I don't need to use the `flags` package here for a single boolean option. Previously I had tried with `flags` but it conflicted with the flags defined by `analyzer.Analyzer`.
-rw-r--r--capturedrefrace.go2
-rw-r--r--cmd/gocapturedrefrace/main.go13
2 files changed, 12 insertions, 3 deletions
diff --git a/capturedrefrace.go b/capturedrefrace.go
index 21a8b2d..b58ed9d 100644
--- a/capturedrefrace.go
+++ b/capturedrefrace.go
@@ -29,8 +29,6 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
-var version = "0.0.1"
-
var Analyzer = &analysis.Analyzer{
Name: "capturedrefrace",
Doc: "reports captured references in goroutine closures",
diff --git a/cmd/gocapturedrefrace/main.go b/cmd/gocapturedrefrace/main.go
index 60c7838..5a8970b 100644
--- a/cmd/gocapturedrefrace/main.go
+++ b/cmd/gocapturedrefrace/main.go
@@ -16,14 +16,25 @@
// along with Gocapturedrefrace. If not, see
// <https://www.gnu.org/licenses/>.
-
package main
import (
+ "os"
+
"golang.org/x/tools/go/analysis/singlechecker"
"gopkg.teddywing.com/capturedrefrace"
)
+var version = "0.0.1"
+
func main() {
+ if len(os.Args) > 1 &&
+ (os.Args[1] == "-V" ||
+ os.Args[1] == "--version") {
+
+ println(version)
+ os.Exit(0)
+ }
+
singlechecker.Main(capturedrefrace.Analyzer)
}