aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/main.go
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-04-28 15:46:01 +0200
committerLinus Nordberg <linus@nordberg.se>2022-04-28 15:46:01 +0200
commit47490448be1b7006641e6badc6a84b1441b27698 (patch)
treefb386e9e6ccb90b368da63d0a8085d114fd8431c /cmd/sigsum-debug/main.go
parent2dcd7bca2f3e69fb6f1770ec0bf740d8956978ca (diff)
parentb270a4c0d10947fe480bad7330b31bb793225968 (diff)
Merge branch 'merge/sigsum-debug'
Diffstat (limited to 'cmd/sigsum-debug/main.go')
-rw-r--r--cmd/sigsum-debug/main.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/cmd/sigsum-debug/main.go b/cmd/sigsum-debug/main.go
new file mode 100644
index 0000000..7a1c894
--- /dev/null
+++ b/cmd/sigsum-debug/main.go
@@ -0,0 +1,65 @@
+// package main provides a tool named sigsum-debug
+//
+// Install:
+//
+// $ go install git.sigsum.org/sigsum-go/cmd/sigsum-debug@latest
+//
+// Usage:
+//
+// $ sigsum-debug help
+//
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+
+ "git.sigsum.org/sigsum-go/cmd/sigsum-debug/head"
+ "git.sigsum.org/sigsum-go/cmd/sigsum-debug/key"
+ "git.sigsum.org/sigsum-go/cmd/sigsum-debug/leaf"
+ "git.sigsum.org/sigsum-go/internal/options"
+)
+
+const usage = `
+sigsum-debug is a tool that helps debug sigsum logs on the command-line.
+It is meant to be used in conjuction with other utilities such as curl.
+
+Usage:
+
+ sigsum-debug help Usage message
+ sigsum-debug key Private and public key utilities
+ sigsum-debug leaf Hash, sign, and verify tree leaves
+ sigsum-debug head Sign and verify tree heads
+
+`
+
+func main() {
+ var err error
+
+ log.SetFlags(0)
+ opt := options.New(os.Args[1:], func() { log.Printf(usage[1:]) }, func(_ *flag.FlagSet) {})
+ switch opt.Name() {
+ case "help":
+ opt.Usage()
+ case "key":
+ err = key.Main(opt.Args())
+ case "leaf":
+ err = leaf.Main(opt.Args())
+ case "head":
+ err = head.Main(opt.Args())
+ default:
+ err = fmt.Errorf(": invalid command %q, try \"help\"", opt.Name())
+ }
+
+ if err != nil {
+ format := "sigsum-debug %s%s"
+ if len(opt.Name()) == 0 {
+ format = "sigsum-debug%s%s"
+ }
+
+ log.Printf(format, opt.Name(), err.Error())
+ os.Exit(1)
+ }
+}