mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Create local store functions
This commit is contained in:
parent
0c5ff0b7bb
commit
5a48ddeb66
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/packwiz/packwiz/core"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -40,12 +41,12 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVar(&modsFolder, "mods-folder", "mods", "The default folder to store mod metadata files in")
|
rootCmd.PersistentFlags().StringVar(&modsFolder, "mods-folder", "mods", "The default folder to store mod metadata files in")
|
||||||
_ = viper.BindPFlag("mods-folder", rootCmd.PersistentFlags().Lookup("mods-folder"))
|
_ = viper.BindPFlag("mods-folder", rootCmd.PersistentFlags().Lookup("mods-folder"))
|
||||||
|
|
||||||
file, err := os.UserConfigDir()
|
file, err := core.GetPackwizLocalStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
file = filepath.Join(file, "packwiz", ".packwiz.toml")
|
file = filepath.Join(file, ".packwiz.toml")
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "The config file to use (default \""+file+"\")")
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "The config file to use (default \""+file+"\")")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,13 +56,13 @@ func initConfig() {
|
|||||||
// Use config file from the flag.
|
// Use config file from the flag.
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
} else {
|
} else {
|
||||||
dir, err := os.UserConfigDir()
|
dir, err := core.GetPackwizLocalStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.AddConfigPath(filepath.Join(dir, "packwiz"))
|
viper.AddConfigPath(dir)
|
||||||
viper.SetConfigName(".packwiz")
|
viper.SetConfigName(".packwiz")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
46
core/storeutil.go
Normal file
46
core/storeutil.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPackwizLocalStore() (string, error) {
|
||||||
|
if //goland:noinspection GoBoolExpressions
|
||||||
|
runtime.GOOS == "linux" {
|
||||||
|
// Prefer $XDG_DATA_HOME over $XDG_CACHE_HOME
|
||||||
|
dataHome := os.Getenv("XDG_DATA_HOME")
|
||||||
|
if dataHome != "" {
|
||||||
|
return filepath.Join(dataHome, "packwiz"), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userConfigDir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return filepath.Join(userConfigDir, "packwiz"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPackwizInstallBinPath() (string, error) {
|
||||||
|
localStore, err := GetPackwizLocalStore()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return filepath.Join(localStore, "bin"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPackwizInstallBinFile() (string, error) {
|
||||||
|
binPath, err := GetPackwizInstallBinPath()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
var exeName string
|
||||||
|
if //goland:noinspection GoBoolExpressions
|
||||||
|
runtime.GOOS == "windows" {
|
||||||
|
exeName = "packwiz.exe"
|
||||||
|
} else {
|
||||||
|
exeName = "packwiz"
|
||||||
|
}
|
||||||
|
return filepath.Join(binPath, exeName), nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user