aboutsummaryrefslogtreecommitdiff
path: root/awwan.go
diff options
context:
space:
mode:
Diffstat (limited to 'awwan.go')
-rw-r--r--awwan.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/awwan.go b/awwan.go
index 0e96c03..f4fe389 100644
--- a/awwan.go
+++ b/awwan.go
@@ -227,6 +227,44 @@ func (aww *Awwan) EnvGet(dir, key string) (val string, err error) {
return val, nil
}
+// EnvKeys load environment files from BaseDir to path and return all its
+// keys.
+// The path is optional, default to BaseDir if its empty.
+func (aww *Awwan) EnvKeys(path string) (keys []string, err error) {
+ var (
+ logp = `EnvKeys`
+
+ dir string
+ fi os.FileInfo
+ )
+
+ if path == `` {
+ path = aww.BaseDir
+ }
+
+ fi, err = os.Stat(path)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+
+ if fi.IsDir() {
+ dir = path
+ } else {
+ dir = filepath.Dir(path)
+ }
+
+ var ses *Session
+
+ ses, err = NewSession(aww, dir)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+
+ keys = ses.vars.Keys()
+
+ return keys, nil
+}
+
// EnvSet set the value in the environment file based on the key.
//
// The key is using the "<section>:<sub>:<name>" format.