From c9aaa2782f61ac495945d601a8e1dedf50ae1f10 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Tue, 12 Oct 2021 10:27:42 -0400 Subject: [PATCH] Add -version flag --- cmd/certspotter/main.go | 2 +- cmd/common.go | 9 +++++++++ cmd/ctparsewatch/main.go | 2 +- version.go | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 version.go diff --git a/cmd/certspotter/main.go b/cmd/certspotter/main.go index c564ff7..da1e4ed 100644 --- a/cmd/certspotter/main.go +++ b/cmd/certspotter/main.go @@ -206,7 +206,7 @@ func processEntry(scanner *certspotter.Scanner, entry *ct.LogEntry) { } func main() { - flag.Parse() + cmd.ParseFlags() if *watchlistFilename == "-" { var err error diff --git a/cmd/common.go b/cmd/common.go index 1bc44f0..692710f 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -33,6 +33,7 @@ var script = flag.String("script", "", "Script to execute when a matching certif var logsURL = flag.String("logs", defaultLogList, "File path or URL of JSON list of logs to monitor") var noSave = flag.Bool("no_save", false, "Do not save a copy of matching certificates") var verbose = flag.Bool("verbose", false, "Be verbose") +var showVersion = flag.Bool("version", false, "Print version and exit") var startAtEnd = flag.Bool("start_at_end", false, "Start monitoring logs from the end rather than the beginning") var allTime = flag.Bool("all_time", false, "Scan certs from all time, not just since last scan") var state *State @@ -298,6 +299,14 @@ func processLog(logInfo *loglist.Log, processCallback certspotter.ProcessCallbac return 0 } +func ParseFlags() { + flag.Parse() + if *showVersion { + fmt.Fprintf(os.Stdout, "Cert Spotter %s\n", certspotter.Version) + os.Exit(0) + } +} + func Main(statePath string, processCallback certspotter.ProcessCallback) int { var err error diff --git a/cmd/ctparsewatch/main.go b/cmd/ctparsewatch/main.go index 71987bb..d9df557 100644 --- a/cmd/ctparsewatch/main.go +++ b/cmd/ctparsewatch/main.go @@ -47,6 +47,6 @@ func processEntry(scanner *certspotter.Scanner, entry *ct.LogEntry) { } func main() { - flag.Parse() + cmd.ParseFlags() os.Exit(cmd.Main(*stateDir, processEntry)) } diff --git a/version.go b/version.go new file mode 100644 index 0000000..844dc2d --- /dev/null +++ b/version.go @@ -0,0 +1,12 @@ +// Copyright (C) 2021 Opsmate, Inc. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License, v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// This software is distributed WITHOUT A WARRANTY OF ANY KIND. +// See the Mozilla Public License for details. + +package certspotter + +const Version = "0.11"