/
root.go
60 lines (52 loc) · 1.14 KB
/
root.go
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
package cmd
import (
"fmt"
"os"
"runtime"
"github.com/go-errors/errors"
irma "github.com/markuskreukniet/irmago-measurements"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "irma",
Short: "IRMA toolkit",
Long: "IRMA toolkit v" + irma.Version + "\nDocumentation: https://irma.app/docs",
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print irma version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(RootCmd.Long)
fmt.Println()
fmt.Println("Version: ", irma.Version)
fmt.Println("OS/Arg: ", runtime.GOOS+"/"+runtime.GOARCH)
},
}
func Execute() {
if err := RootCmd.Execute(); err != nil {
os.Exit(-1)
}
}
func init() {
RootCmd.AddCommand(versionCmd)
}
func die(message string, err error) {
var m string
if message != "" {
m = message
}
if err != nil {
if message != "" {
m += ": "
}
if e, ok := err.(*errors.Error); ok && logger.IsLevelEnabled(logrus.DebugLevel) {
m += e.ErrorStack()
} else {
m += err.Error()
}
}
logger.Error(m)
os.Exit(1)
}