forked from google/go-tpm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
62 lines (53 loc) · 1.25 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
61
62
// Package cmd contains a CLI to interact with TPM.
package cmd
import (
"fmt"
"io"
"io/ioutil"
"os"
"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/prototext"
)
// RootCmd is the entrypoint for gotpm.
var RootCmd = &cobra.Command{
Use: "gotpm",
Long: `Command line tool for the go-tpm TSS
This tool allows performing TPM2 operations from the command line.
See the per-command documentation for more information.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if quiet && verbose {
return fmt.Errorf("cannot specify both --quiet and --verbose")
}
cmd.SilenceUsage = true
return nil
},
}
var (
quiet bool
verbose bool
)
func init() {
RootCmd.PersistentFlags().BoolVar(&quiet, "quiet", false,
"print nothing if command is successful")
RootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false,
"print additional info to stdout")
hideHelp(RootCmd)
}
func messageOutput() io.Writer {
if quiet {
return ioutil.Discard
}
return os.Stdout
}
func debugOutput() io.Writer {
if verbose {
return os.Stdout
}
return ioutil.Discard
}
// Default Text Marshalling options
var marshalOptions = prototext.MarshalOptions{
Multiline: true,
EmitASCII: true,
}
var unmarshalOptions = prototext.UnmarshalOptions{}