Add -version flag

This commit is contained in:
Andrew Ayer 2021-10-12 10:27:42 -04:00
parent 54f34077d3
commit c9aaa2782f
4 changed files with 23 additions and 2 deletions

View File

@ -206,7 +206,7 @@ func processEntry(scanner *certspotter.Scanner, entry *ct.LogEntry) {
} }
func main() { func main() {
flag.Parse() cmd.ParseFlags()
if *watchlistFilename == "-" { if *watchlistFilename == "-" {
var err error var err error

View File

@ -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 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 noSave = flag.Bool("no_save", false, "Do not save a copy of matching certificates")
var verbose = flag.Bool("verbose", false, "Be verbose") 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 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 allTime = flag.Bool("all_time", false, "Scan certs from all time, not just since last scan")
var state *State var state *State
@ -298,6 +299,14 @@ func processLog(logInfo *loglist.Log, processCallback certspotter.ProcessCallbac
return 0 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 { func Main(statePath string, processCallback certspotter.ProcessCallback) int {
var err error var err error

View File

@ -47,6 +47,6 @@ func processEntry(scanner *certspotter.Scanner, entry *ct.LogEntry) {
} }
func main() { func main() {
flag.Parse() cmd.ParseFlags()
os.Exit(cmd.Main(*stateDir, processEntry)) os.Exit(cmd.Main(*stateDir, processEntry))
} }

12
version.go Normal file
View File

@ -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"