aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-09-17 23:32:41 +0000
committerFuwn <[email protected]>2024-09-17 23:32:41 +0000
commit92a86b59a4d9494b2f0b193dd815bec266b5a471 (patch)
tree6194f56995872537630bd510a6248582e2bed033
parentfeat(rui): notifications (diff)
downloadrui-92a86b59a4d9494b2f0b193dd815bec266b5a471.tar.xz
rui-92a86b59a4d9494b2f0b193dd815bec266b5a471.zip
feat(rui): top-level configuration initialisation
-rw-r--r--rui.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/rui.go b/rui.go
index 3b0e9cd..6495408 100644
--- a/rui.go
+++ b/rui.go
@@ -10,6 +10,30 @@ import (
"github.com/urfave/cli/v2"
)
+type Configuration struct {
+ Notify bool `json:"notify"`
+}
+
+var configuration Configuration
+
+func init() {
+ configurationPath := os.Getenv("RUI_CONFIG")
+
+ if configurationPath == "" {
+ configurationPath = os.Getenv("XDG_CONFIG_HOME") + "/rui/config.json"
+ }
+
+ content, err := os.ReadFile(configurationPath)
+
+ if err != nil {
+ return
+ }
+
+ if err := json.Unmarshal(content, &configuration); err != nil {
+ return
+ }
+}
+
func main() {
(&cli.App{
Name: "rui",
@@ -206,23 +230,7 @@ func Command(name string, args ...string) error {
return cmd.Run()
}
-type Configuration struct {
- Notify bool `json:"notify"`
-}
-
func Notify(message string) error {
- content, err := os.ReadFile(os.Getenv("XDG_CONFIG_HOME"))
-
- if err != nil {
- return err
- }
-
- var configuration Configuration
-
- if err := json.Unmarshal(content, &configuration); err != nil {
- return err
- }
-
notifySend, err := exec.LookPath("notify-send")
if err != nil {