This is an automated email from the ASF dual-hosted git repository.

mrutkowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new 479d769  Honor WSK_CONFIG_FILE if variable is set (#1054)
479d769 is described below

commit 479d769c569dda174ba3e04318378e581acd6750
Author: Alvaro Lopez Garcia <[email protected]>
AuthorDate: Tue Sep 10 01:34:48 2019 +0000

    Honor WSK_CONFIG_FILE if variable is set (#1054)
    
    The OpenWhisk CLI (wsk) allows to set the WSK_CONFIG_FILE to point to
    the configuration file. wskdeploy does not honor this environment
    variable and it only relies on the --config flag. This change allows to
    use the environment variable (if present), making it consistent with the
    wsk CLI behaviour.
    
    Fixes #809
    Fixes #436
---
 cmd/root.go | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 57c8966..44f5e88 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -102,20 +102,31 @@ func init() {
 func initConfig() {
        userHome := utils.GetHomeDirectory()
        defaultPath := path.Join(userHome, whisk.DEFAULT_LOCAL_CONFIG)
-       if utils.Flags.CfgFile != "" {
 
-               // Read the file as a wskprops file, to check if it is valid.
-               _, err := whisk.ReadProps(utils.Flags.CfgFile)
-               if err != nil {
-                       utils.Flags.CfgFile = defaultPath
-                       warn := 
wski18n.T(wski18n.ID_WARN_CONFIG_INVALID_X_path_X,
-                               map[string]interface{}{
-                                       wski18n.KEY_PATH: utils.Flags.CfgFile})
-                       wskprint.PrintOpenWhiskWarning(warn)
-               }
+       // Precedence order for reading the configuration file should be:
+       // 1. --config
+       // 2. ENV variable WSK_CONFIG_FILE
+       // 3. Default $HOME/.wskprops
+       cfgFiles := []string{
+               utils.Flags.CfgFile,
+               os.Getenv("WSK_CONFIG_FILE"),
+               defaultPath,
+       }
 
-       } else {
-               utils.Flags.CfgFile = defaultPath
+       for _, cfgFile := range cfgFiles {
+               if cfgFile != "" {
+                       // Read the file as a wskprops file, to check if it is 
valid.
+                       _, err := whisk.ReadProps(cfgFile)
+                       if err != nil {
+                               warn := 
wski18n.T(wski18n.ID_WARN_CONFIG_INVALID_X_path_X,
+                                       map[string]interface{}{
+                                               wski18n.KEY_PATH: 
utils.Flags.CfgFile})
+                               wskprint.PrintOpenWhiskWarning(warn)
+                       } else {
+                               utils.Flags.CfgFile = cfgFile
+                               break
+                       }
+               }
        }
 }
 

Reply via email to