@@ -43,16 +43,17 @@ var ConfigCmd = &cobra.Command{
43
43
44
44
// Config defines the config schema
45
45
type Config struct {
46
- Endpoint string `yaml:"endpoint"`
47
- Wallet string `yaml:"wallet"`
48
- Aliases map [string ]string `yaml:"aliases"`
46
+ Wallet string `yaml:"wallet"`
47
+ Endpoint string `yaml:"endpoint"`
48
+ SecureConnect bool `yaml:"secureConnect"`
49
+ Aliases map [string ]string `yaml:"aliases"`
49
50
}
50
51
51
52
var (
52
53
// ReadConfig represents the current config read from local
53
54
ReadConfig Config
54
- // IsInsecure represents the connect option of grpc dial
55
- IsInsecure bool
55
+ // Insecure represents the insecure connect option of grpc dial, default is false
56
+ Insecure = false
56
57
)
57
58
58
59
func init () {
@@ -63,19 +64,22 @@ func init() {
63
64
DefaultConfigFile = ConfigDir + "/config.default"
64
65
var err error
65
66
ReadConfig , err = LoadConfig ()
66
- if err != nil || ReadConfig .Wallet == "" {
67
- if ! os .IsNotExist (err ) || ReadConfig .Wallet == "" {
68
- ReadConfig .Wallet = ConfigDir
69
- out , err := yaml .Marshal (& ReadConfig )
70
- if err != nil {
71
- log .L ().Panic (err .Error ())
72
- }
73
- if err := ioutil .WriteFile (DefaultConfigFile , out , 0600 ); err != nil {
74
- log .L ().Panic (fmt .Sprintf ("Failed to write to config file %s." , DefaultConfigFile ))
75
- }
76
- } else {
67
+ if err != nil || len (ReadConfig .Wallet ) == 0 {
68
+ if err != nil && ! os .IsNotExist (err ) {
69
+ log .L ().Panic (err .Error ()) // Config file exists but error occurs
70
+ }
71
+ ReadConfig .Wallet = ConfigDir
72
+ if os .IsNotExist (err ) {
73
+ ReadConfig .SecureConnect = true
74
+ }
75
+ out , err := yaml .Marshal (& ReadConfig )
76
+ if err != nil {
77
77
log .L ().Panic (err .Error ())
78
78
}
79
+ if err := ioutil .WriteFile (DefaultConfigFile , out , 0600 ); err != nil {
80
+ log .L ().Panic (fmt .Sprintf ("Failed to write to config file %s." , DefaultConfigFile ))
81
+ }
82
+
79
83
}
80
84
ConfigCmd .AddCommand (configGetCmd )
81
85
ConfigCmd .AddCommand (configSetCmd )
0 commit comments