aboutsummaryrefslogtreecommitdiff
path: root/awwan.go
diff options
context:
space:
mode:
Diffstat (limited to 'awwan.go')
-rw-r--r--awwan.go46
1 files changed, 30 insertions, 16 deletions
diff --git a/awwan.go b/awwan.go
index f4fe389..d604d8d 100644
--- a/awwan.go
+++ b/awwan.go
@@ -9,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
@@ -215,6 +216,13 @@ func (aww *Awwan) EnvGet(dir, key string) (val string, err error) {
return ``, fmt.Errorf(`%s: empty key`, logp)
}
+ var unqkey string
+
+ unqkey, err = strconv.Unquote(key)
+ if err == nil {
+ key = unqkey
+ }
+
var ses *Session
ses, err = NewSession(aww, dir)
@@ -267,13 +275,17 @@ func (aww *Awwan) EnvKeys(path string) (keys []string, err error) {
// EnvSet set the value in the environment file based on the key.
//
-// The key is using the "<section>:<sub>:<name>" format.
+// The file parameter point to "awwan.env" or INI formatted file.
//
-// The file is optional, if its empty default to "awwan.env" in the current
-// directory.
-func (aww *Awwan) EnvSet(key, val, file string) (err error) {
+// The key is using the "<section>:<sub>:<name>" format.
+func (aww *Awwan) EnvSet(file, key, val string) (err error) {
var logp = `EnvSet`
+ file = strings.TrimSpace(file)
+ if len(file) == 0 {
+ return fmt.Errorf(`%s: empty file`, logp)
+ }
+
key = strings.TrimSpace(key)
if len(key) == 0 {
return fmt.Errorf(`%s: empty key`, logp)
@@ -284,20 +296,15 @@ func (aww *Awwan) EnvSet(key, val, file string) (err error) {
return fmt.Errorf(`%s: empty value`, logp)
}
- file = strings.TrimSpace(file)
- if len(file) == 0 {
- file = filepath.Join(aww.currDir, defEnvFileName)
- }
-
- var env *ini.Ini
-
- env, err = ini.Open(file)
- if err != nil {
- return fmt.Errorf(`%s: %w`, logp, err)
+ var (
+ tags []string
+ unqkey string
+ )
+ unqkey, err = strconv.Unquote(key)
+ if err == nil {
+ key = unqkey
}
- var tags []string
-
tags = ini.ParseTag(key)
if len(tags[0]) == 0 {
@@ -307,6 +314,13 @@ func (aww *Awwan) EnvSet(key, val, file string) (err error) {
return fmt.Errorf(`%s: missing name in key`, logp)
}
+ var env *ini.Ini
+
+ env, err = ini.Open(file)
+ if err != nil {
+ return fmt.Errorf(`%s: %w`, logp, err)
+ }
+
var ok bool
ok = env.Set(tags[0], tags[1], tags[2], val)