Skip to content

Commit

Permalink
[kvsp] Update usage printing
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed May 16, 2020
1 parent 6c5d23d commit 89c076a
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions kvsp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ func (i *arrayFlags) Set(value string) error {
return nil
}

func fatalExit(err error) {
log.Fatal(err)
os.Exit(1)
}

func fatalExitWithMsg(format string, args ...interface{}) {
fatalExit(fmt.Errorf(format, args...))
}

func write16le(out []byte, val int) {
out[0] = byte(val & 0xff)
out[1] = byte((val >> 8) & 0xff)
Expand Down Expand Up @@ -439,7 +430,7 @@ func doDebug() error {
// Get the path of cahp-sim
path, err := getPathOf("CAHP_SIM")
if err != nil {
fatalExit(err)
return err
}

// Run
Expand Down Expand Up @@ -762,27 +753,35 @@ func doVersion() error {
return nil
}

func printUsageAndExit() {
fatalExitWithMsg(`
Usage:
kvsp cc OPTIONS...
kvsp debug OPTIONS...
kvsp dec OPTIONS...
kvsp emu OPTIONS...
kvsp enc OPTIONS...
kvsp genkey OPTIONS...
kvsp genbkey OPTIONS...
kvsp run OPTIONS...
`)
}

func main() {
if envvarVerbose := os.Getenv("KVSP_VERBOSE"); envvarVerbose == "1" {
flagVerbose = true
}

flag.Usage = func() {
fmt.Fprintf(os.Stderr, `Usage: %s COMMAND [OPTIONS]... ARGS...
KVSP is the first virtual secure platform in the world, which makes your life better.
Commands:
cc
debug
dec
emu
enc
genkey
genbkey
plainpacket
resume
run
version
`, os.Args[0])
flag.PrintDefaults()
}

if len(os.Args) <= 1 {
printUsageAndExit()
flag.Usage()
os.Exit(1)
}

var err error
Expand Down Expand Up @@ -810,10 +809,12 @@ func main() {
case "version":
err = doVersion()
default:
printUsageAndExit()
flag.Usage()
os.Exit(1)
}

if err != nil {
fatalExit(err)
log.Fatal(err)
os.Exit(1)
}
}

0 comments on commit 89c076a

Please sign in to comment.