diff --git a/dfssc/cmd/root.go b/dfssc/cmd/root.go index dd65f9ba71e980c2781fe82d9f51c38ff475a536..a319d76ea6a95b696ea5442b9547e391aede292c 100644 --- a/dfssc/cmd/root.go +++ b/dfssc/cmd/root.go @@ -24,7 +24,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`, }, PersistentPreRun: func(cmd *cobra.Command, args []string) { net.DefaultTimeout = viper.GetDuration("timeout") - dapi.Configure(viper.GetString("demo") != "", viper.GetString("demo"), "client") + dapi.Configure(viper.GetBool("verbose"), viper.GetString("demo") != "", viper.GetString("demo"), "client") }, PersistentPostRun: func(cmd *cobra.Command, args []string) { dapi.DClose() diff --git a/dfssd/api/client.go b/dfssd/api/client.go index 4485698f0098269256939167afead60c705438a8..537ff7dc227773f5cfc15be19925f077261afb85 100644 --- a/dfssd/api/client.go +++ b/dfssd/api/client.go @@ -1,6 +1,7 @@ package api import ( + "fmt" "time" "golang.org/x/net/context" @@ -10,7 +11,7 @@ import ( var ( address, identifier string - demo bool + demo, verbose bool // lazy initializer dial *grpc.ClientConn demoClient DemonstratorClient @@ -18,10 +19,11 @@ var ( // Configure is used to update current parameters. // Call it at least one time before the first DLog call. -func Configure(activated bool, addrport, id string) { +func Configure(verbswitch, activated bool, addrport, id string) { address = addrport identifier = id demo = activated + verbose = verbswitch } // SetIdentifier updates the current client identifier. @@ -58,6 +60,11 @@ func DClose() { // // The client is dialed in a lazy way func DLog(log string) { + // check verbose switch + if verbose { + fmt.Println(log) + } + // check demo switch if !demo { return diff --git a/dfssp/cmd/root.go b/dfssp/cmd/root.go index 03cd567450f05b33405d9b4d3a9479f0c6cb4479..8def069e7c3e57724166a788591af55d413f7486 100644 --- a/dfssp/cmd/root.go +++ b/dfssp/cmd/root.go @@ -20,7 +20,7 @@ Users and Contracts manager`, _ = cmd.Help() }, PersistentPreRun: func(cmd *cobra.Command, args []string) { - dapi.Configure(viper.GetString("demo") != "", viper.GetString("demo"), "platform") + dapi.Configure(viper.GetBool("verbose"), viper.GetString("demo") != "", viper.GetString("demo"), "platform") }, PersistentPostRun: func(cmd *cobra.Command, args []string) { dapi.DClose() diff --git a/dfsst/cmd/root.go b/dfsst/cmd/root.go index f620db2b6df6109780746d2702ae3ad74791116d..c166472919d5b0896a96723837b14620078b1edf 100644 --- a/dfsst/cmd/root.go +++ b/dfsst/cmd/root.go @@ -5,6 +5,7 @@ import ( "fmt" "dfss" + dapi "dfss/dfssd/api" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -22,6 +23,12 @@ Sign your 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.GetBool("verbose"), viper.GetString("demo") != "", viper.GetString("demo"), "ttp") + }, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + dapi.DClose() + }, } // All of the flags will be gathered by viper, this is why diff --git a/dfsst/cmd/start.go b/dfsst/cmd/start.go index c36cab923075b22996cedf8fbad9b78b1cc31cc0..c1a484f1abaa3d7ff1e243b7522d85f475ddfbec 100644 --- a/dfsst/cmd/start.go +++ b/dfsst/cmd/start.go @@ -20,9 +20,6 @@ var startCmd = &cobra.Command{ Fill the DFSS_TTP_PASSWORD environment variable if the private key is enciphered`, Run: func(cmd *cobra.Command, args []string) { - demo := viper.GetString("demo") - dapi.Configure(demo != "", demo, "ttp") - srv := server.GetServer() addrPort := viper.GetString("address") + ":" + strconv.Itoa(viper.GetInt("port"))