aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/main.go
blob: af2093c0d30cec9a8e5da43d201b13ca8a418e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 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/cmd/sigsum-debug/spam"
	"git.sigsum.org/sigsum-go/internal/options"
)

const usage = `
sigsum-debug is a tool that helps debug sigsum logs on the command-line

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
  sigsum-debug spam  Send many requests to a sigsum log

`

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())
	case "spam":
		err = spam.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)
	}
}