Commit 101a357a authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch 'fix_13_verbose_flag' into 'master'

[demo] Verbose flag print DLog to stdout

Should fix #13

See merge request !88
parents 2f3b6c55 64ba9b13
Pipeline #2204 passed with stages
......@@ -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()
......
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
......
......@@ -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()
......
......@@ -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
......
......@@ -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"))
......
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