aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2018-08-08 21:52:34 +0100
committerNiall Sheridan <nsheridan@gmail.com>2018-08-08 22:54:43 +0100
commit9f8f0194a3c21e640a5b917f86bf204c014d730d (patch)
tree6921f64032a8eea7adeedfba156b62e2e6925969 /client
parent12417f0dddf4be86aa5b9a4cb25bf48a4e301086 (diff)
Correct client behaviours for option handling
A config file is not required - don't error if one doesn't exist. Don't overwrite default options with an empty string.
Diffstat (limited to 'client')
-rw-r--r--client/config.go12
-rw-r--r--client/keys.go4
2 files changed, 11 insertions, 5 deletions
diff --git a/client/config.go b/client/config.go
index eae3bfa..4536994 100644
--- a/client/config.go
+++ b/client/config.go
@@ -1,6 +1,8 @@
package client
import (
+ "os"
+
"github.com/mitchellh/go-homedir"
"github.com/spf13/pflag"
"github.com/spf13/viper"
@@ -28,10 +30,12 @@ func setDefaults() {
// ReadConfig reads the client configuration from a file into a Config struct.
func ReadConfig(path string) (*Config, error) {
setDefaults()
- viper.SetConfigFile(path)
- viper.SetConfigType("hcl")
- if err := viper.ReadInConfig(); err != nil {
- return nil, err
+ if _, err := os.Stat(path); err == nil {
+ viper.SetConfigFile(path)
+ viper.SetConfigType("hcl")
+ if err := viper.ReadInConfig(); err != nil {
+ return nil, err
+ }
}
c := &Config{}
if err := viper.Unmarshal(c); err != nil {
diff --git a/client/keys.go b/client/keys.go
index b488ea2..f573136 100644
--- a/client/keys.go
+++ b/client/keys.go
@@ -59,7 +59,9 @@ func pemBlockForKey(priv interface{}) (*pem.Block, error) {
// Default is "rsa"
func KeyType(keyType string) KeyOption {
return func(o *options) {
- o.keytype = keyType
+ if keyType != "" {
+ o.keytype = keyType
+ }
}
}