root.go 2.54 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
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
	"dfss"
	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) {
		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
35
	// Bind flags to the dfssc command
ElyKar's avatar
ElyKar committed
36
37
38
39
40
41
42
43
	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")

44
	signCmd.Flags().Duration("timeout", time.Minute, "time to wait before fallback")
Loïck Bonniot's avatar
Loïck Bonniot committed
45
46
	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
47

ElyKar's avatar
ElyKar committed
48
49
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"))

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

}