Commit 64ba9b13 authored by Richer Maximilien's avatar Richer Maximilien

[demo] Verbose flag print DLog to stdout

parent 9cba231d
Pipeline #2196 passed with stage
...@@ -24,7 +24,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`, ...@@ -24,7 +24,7 @@ A tool to sign multiparty contract using a secure cryptographic protocol`,
}, },
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
net.DefaultTimeout = viper.GetDuration("timeout") 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) { PersistentPostRun: func(cmd *cobra.Command, args []string) {
dapi.DClose() dapi.DClose()
......
package api package api
import ( import (
"fmt"
"time" "time"
"golang.org/x/net/context" "golang.org/x/net/context"
...@@ -10,7 +11,7 @@ import ( ...@@ -10,7 +11,7 @@ import (
var ( var (
address, identifier string address, identifier string
demo bool demo, verbose bool
// lazy initializer // lazy initializer
dial *grpc.ClientConn dial *grpc.ClientConn
demoClient DemonstratorClient demoClient DemonstratorClient
...@@ -18,10 +19,11 @@ var ( ...@@ -18,10 +19,11 @@ var (
// Configure is used to update current parameters. // Configure is used to update current parameters.
// Call it at least one time before the first DLog call. // 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 address = addrport
identifier = id identifier = id
demo = activated demo = activated
verbose = verbswitch
} }
// SetIdentifier updates the current client identifier. // SetIdentifier updates the current client identifier.
...@@ -58,6 +60,11 @@ func DClose() { ...@@ -58,6 +60,11 @@ func DClose() {
// //
// The client is dialed in a lazy way // The client is dialed in a lazy way
func DLog(log string) { func DLog(log string) {
// check verbose switch
if verbose {
fmt.Println(log)
}
// check demo switch // check demo switch
if !demo { if !demo {
return return
......
...@@ -20,7 +20,7 @@ Users and Contracts manager`, ...@@ -20,7 +20,7 @@ Users and Contracts manager`,
_ = cmd.Help() _ = cmd.Help()
}, },
PersistentPreRun: func(cmd *cobra.Command, args []string) { 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) { PersistentPostRun: func(cmd *cobra.Command, args []string) {
dapi.DClose() dapi.DClose()
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"dfss" "dfss"
dapi "dfss/dfssd/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
...@@ -22,6 +23,12 @@ Sign your contract using a secure cryptographic protocol`, ...@@ -22,6 +23,12 @@ Sign your contract using a secure cryptographic protocol`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help() _ = 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 // All of the flags will be gathered by viper, this is why
......
...@@ -20,9 +20,6 @@ var startCmd = &cobra.Command{ ...@@ -20,9 +20,6 @@ var startCmd = &cobra.Command{
Fill the DFSS_TTP_PASSWORD environment variable if the private key is enciphered`, Fill the DFSS_TTP_PASSWORD environment variable if the private key is enciphered`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
demo := viper.GetString("demo")
dapi.Configure(demo != "", demo, "ttp")
srv := server.GetServer() srv := server.GetServer()
addrPort := viper.GetString("address") + ":" + strconv.Itoa(viper.GetInt("port")) addrPort := viper.GetString("address") + ":" + strconv.Itoa(viper.GetInt("port"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment