root.go 2.71 KB
Newer Older
1
// Package cmd handles flags and commands management.
ElyKar's avatar
ElyKar committed
2
3
4
package cmd

import (
5
6
	"time"

ElyKar's avatar
ElyKar committed
7
	"dfss"
8
	"dfss/net"
ElyKar's avatar
ElyKar committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	dapi "dfss/dfssd/api"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

// RootCmd is the main command for the dfssc application
var RootCmd = &cobra.Command{
	Use:   "dfssc",
	Short: "DFSS command-line client",
	Long: `Command-line client v` + dfss.Version + ` for the
Distributed Fair Signing System project

A tool to sign multiparty contract using a secure cryptographic protocol`,
	Run: func(cmd *cobra.Command, args []string) {
		_ = cmd.Help()
	},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
26
		net.DefaultTimeout = viper.GetDuration("timeout")
ElyKar's avatar
ElyKar committed
27
28
29
30
31
32
33
34
35
36
		dapi.Configure(viper.GetString("demo") != "", viper.GetString("demo"), "client")
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		dapi.DClose()
	},
}

// All of the flags will be gathered by viper, this is why
// we do not store their values
func init() {
Loïck Bonniot's avatar
Loïck Bonniot committed
37
	// Bind flags to the dfssc command
ElyKar's avatar
ElyKar committed
38
39
40
41
42
43
44
	RootCmd.PersistentFlags().BoolP("verbose", "v", false, "print verbose messages")
	RootCmd.PersistentFlags().String("ca", "ca.pem", "path to the root certificate")
	RootCmd.PersistentFlags().String("cert", "cert.pem", "path to the user's certificate")
	RootCmd.PersistentFlags().String("key", "key.pem", "path to the user's private key")
	RootCmd.PersistentFlags().StringP("demo", "d", "", "demonstrator address and port, empty will disable it")
	RootCmd.PersistentFlags().String("host", "localhost:9000", "host of the dfss platform")
	RootCmd.PersistentFlags().IntP("port", "p", 9005, "port to use for P2P communication between clients")
45
	RootCmd.PersistentFlags().Duration("timeout", 10*time.Second, "time to wait for connection and evidences before failing")
ElyKar's avatar
ElyKar committed
46

Loïck Bonniot's avatar
Loïck Bonniot committed
47
48
	signCmd.Flags().Duration("slowdown", 0, "delay between each promises round (test only)")
	signCmd.Flags().Int("stopbefore", 0, "stop signature just before the promises round n, -1 to stop right before signature round (test only)")
Loïck Bonniot's avatar
Loïck Bonniot committed
49

ElyKar's avatar
ElyKar committed
50
51
52
53
54
55
56
57
	// Store flag values into viper
	_ = viper.BindPFlag("verbose", RootCmd.PersistentFlags().Lookup("verbose"))
	_ = viper.BindPFlag("file_ca", RootCmd.PersistentFlags().Lookup("ca"))
	_ = viper.BindPFlag("file_cert", RootCmd.PersistentFlags().Lookup("cert"))
	_ = viper.BindPFlag("file_key", RootCmd.PersistentFlags().Lookup("key"))
	_ = viper.BindPFlag("demo", RootCmd.PersistentFlags().Lookup("demo"))
	_ = viper.BindPFlag("local_port", RootCmd.PersistentFlags().Lookup("port"))
	_ = viper.BindPFlag("platform_addrport", RootCmd.PersistentFlags().Lookup("host"))
58
	_ = viper.BindPFlag("timeout", RootCmd.PersistentFlags().Lookup("timeout"))
ElyKar's avatar
ElyKar committed
59
60

	// Bind subcommands to root
61
	RootCmd.AddCommand(dfss.VersionCmd, registerCmd, authCmd, newCmd, showCmd, fetchCmd, importCmd, exportCmd, signCmd)
ElyKar's avatar
ElyKar committed
62
63

}