main.go 1.8 KB
Newer Older
Loïck Bonniot's avatar
Loïck Bonniot committed
1 2 3 4 5 6 7 8 9 10
package main

import (
	"dfss"
	"flag"
	"fmt"
	"runtime"
)

var (
11 12 13 14 15
	verbose  bool
	fca      string // Path to the CA
	fcert    string // Path to the certificate
	fkey     string // Path to the private key
	addrPort string // Address and port of the platform
Loïck Bonniot's avatar
Loïck Bonniot committed
16 17 18 19 20
)

func init() {

	flag.BoolVar(&verbose, "v", false, "Print verbose messages")
21 22
	flag.StringVar(&fca, "ca", "ca.pem", "Path to the root certificate")
	flag.StringVar(&fcert, "cert", "cert.pem", "Path to the user certificate")
Loïck Bonniot's avatar
Loïck Bonniot committed
23 24
	flag.StringVar(&fkey, "key", "key.pem", "Path to the private key")
	flag.StringVar(&addrPort, "host", "localhost:9000", "Host of the DFSS platform")
Loïck Bonniot's avatar
Loïck Bonniot committed
25 26 27 28 29 30

	flag.Usage = func() {
		fmt.Println("DFSS client command line v" + dfss.Version)
		fmt.Println("A tool to sign multiparty contracts")

		fmt.Println("\nUsage:")
31
		fmt.Println("  dfssc [flags] command")
Loïck Bonniot's avatar
Loïck Bonniot committed
32 33

		fmt.Println("\nThe commands are:")
34 35 36 37 38 39 40 41
		fmt.Println("  help       print this help")
		fmt.Println("  version    print dfss client version")
		fmt.Println("  register   register a new client")
		fmt.Println("  auth       authenticate a new client")
		fmt.Println("  new        create a new contract")
		fmt.Println("  show <c>   print contract information from file c")
		fmt.Println("  export <c> export certificate and private key of the user to file c")
		fmt.Println("  import <c> import private key and certificate from file c")
Loïck Bonniot's avatar
Loïck Bonniot committed
42 43 44 45 46 47 48 49 50 51

		fmt.Println("\nFlags:")
		flag.PrintDefaults()

		fmt.Println()
	}
}

func main() {
	flag.Parse()
52

Loïck Bonniot's avatar
Loïck Bonniot committed
53 54 55 56 57
	command := flag.Arg(0)

	switch command {
	case "version":
		fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
58
	case "register":
Loïck Bonniot's avatar
Loïck Bonniot committed
59 60 61 62 63
		registerUser()
	case "auth":
		authUser()
	case "new":
		newContract()
Loïck Bonniot's avatar
Loïck Bonniot committed
64 65
	case "show":
		showContract(flag.Arg(1))
66 67 68 69
	case "export":
		exportConf(flag.Arg(1))
	case "import":
		importConf(flag.Arg(1))
Loïck Bonniot's avatar
Loïck Bonniot committed
70 71 72 73
	default:
		flag.Usage()
	}
}