aboutsummaryrefslogtreecommitdiffstats
path: root/src/p_options.go
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2022-04-01 19:44:27 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2022-04-01 19:44:27 +0200
commitb5b54feb70ba1dabc2ef425679f3c569b4e199fa (patch)
treee1f1605ab39455479d7d6c9c30e4e6f09badf729 /src/p_options.go
parentRandom works fine (diff)
downloadgo2work-b5b54feb70ba1dabc2ef425679f3c569b4e199fa.tar.gz
go2work-b5b54feb70ba1dabc2ef425679f3c569b4e199fa.tar.bz2
go2work-b5b54feb70ba1dabc2ef425679f3c569b4e199fa.tar.xz
go2work-b5b54feb70ba1dabc2ef425679f3c569b4e199fa.tar.zst
go2work-b5b54feb70ba1dabc2ef425679f3c569b4e199fa.zip
In progress
Diffstat (limited to 'src/p_options.go')
-rw-r--r--src/p_options.go37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/p_options.go b/src/p_options.go
index 8abd3c2..ea8f9f5 100644
--- a/src/p_options.go
+++ b/src/p_options.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* go2work: src/p_options.go
- * Fri Apr 1 17:16:04 CEST 2022
+ * Fri Apr 1 19:44:09 CEST 2022
* Joe
*
* Options parsing.
@@ -47,8 +47,18 @@
package main
+import (
+ "log"
+ "os"
+)
+
func parse_options() Options {
options := init_def_options()
+ options_file := find_options_file()
+ if options_file == "" {
+ return options
+ }
+ options = parse_toml_file(options_file, options)
return options
}
@@ -62,3 +72,28 @@ func init_def_options() Options {
}
return options
}
+
+func find_options_file() string {
+ val, exists := os.LookupEnv("XDG_CONFIG_HOME")
+ var file_path string
+ if exists == true {
+ file_path = val + "/" + OPTIONS_FILE
+ if check_file_exists(file_path) == true {
+ return file_path
+ }
+ }
+ dir, err := os.UserHomeDir()
+ if err != nil {
+ log.Fatal(err)
+ }
+ file_path = dir + "/.config/" + OPTIONS_FILE
+ if check_file_exists(file_path) == true {
+ return file_path
+ }
+ return ""
+}
+
+func parse_toml_file(options_file string, def_options Options) Options {
+ options := def_options
+ return options
+}