|
|
@@ -1,6 +1,7 @@
|
|
|
package config
|
|
|
|
|
|
import (
|
|
|
+ "cmp"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
@@ -695,19 +696,22 @@ func hasAWSCredentials(env env.Env) bool {
|
|
|
|
|
|
// GlobalConfig returns the global configuration file path for the application.
|
|
|
func GlobalConfig() string {
|
|
|
- xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
|
|
|
- if xdgConfigHome != "" {
|
|
|
+ if crushGlobal := os.Getenv("CRUSH_GLOBAL_CONFIG"); crushGlobal != "" {
|
|
|
+ return filepath.Join(crushGlobal, fmt.Sprintf("%s.json", appName))
|
|
|
+ }
|
|
|
+ if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
|
|
|
return filepath.Join(xdgConfigHome, appName, fmt.Sprintf("%s.json", appName))
|
|
|
}
|
|
|
-
|
|
|
return filepath.Join(home.Dir(), ".config", appName, fmt.Sprintf("%s.json", appName))
|
|
|
}
|
|
|
|
|
|
// GlobalConfigData returns the path to the main data directory for the application.
|
|
|
// this config is used when the app overrides configurations instead of updating the global config.
|
|
|
func GlobalConfigData() string {
|
|
|
- xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
|
|
- if xdgDataHome != "" {
|
|
|
+ if crushData := os.Getenv("CRUSH_GLOBAL_DATA"); crushData != "" {
|
|
|
+ return filepath.Join(crushData, fmt.Sprintf("%s.json", appName))
|
|
|
+ }
|
|
|
+ if xdgDataHome := os.Getenv("XDG_DATA_HOME"); xdgDataHome != "" {
|
|
|
return filepath.Join(xdgDataHome, appName, fmt.Sprintf("%s.json", appName))
|
|
|
}
|
|
|
|
|
|
@@ -715,10 +719,10 @@ func GlobalConfigData() string {
|
|
|
// for windows, it should be in `%LOCALAPPDATA%/crush/`
|
|
|
// for linux and macOS, it should be in `$HOME/.local/share/crush/`
|
|
|
if runtime.GOOS == "windows" {
|
|
|
- localAppData := os.Getenv("LOCALAPPDATA")
|
|
|
- if localAppData == "" {
|
|
|
- localAppData = filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Local")
|
|
|
- }
|
|
|
+ localAppData := cmp.Or(
|
|
|
+ os.Getenv("LOCALAPPDATA"),
|
|
|
+ filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Local"),
|
|
|
+ )
|
|
|
return filepath.Join(localAppData, appName, fmt.Sprintf("%s.json", appName))
|
|
|
}
|
|
|
|