mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-06-25 14:42:51 +00:00
Fix config path resolver
This commit is contained in:
parent
989ed43455
commit
5bbfc6e049
@ -2,24 +2,23 @@ package files
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/adrg/xdg"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/adrg/xdg"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var paths struct {
|
var paths struct {
|
||||||
tokensJSON string
|
tokensJSON string
|
||||||
registrationCredentialsJSON string
|
registrationCredentialsJSON string
|
||||||
fixedCredentialsJSON string
|
fixedCredentialsJSON string
|
||||||
configINI string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TokensJSON() string { return paths.tokensJSON }
|
func TokensJSON() string { return paths.tokensJSON }
|
||||||
func RegistrationCredentialsJSON() string { return paths.registrationCredentialsJSON }
|
func RegistrationCredentialsJSON() string { return paths.registrationCredentialsJSON }
|
||||||
func FixedCredentialsJSON() string { return paths.fixedCredentialsJSON }
|
func FixedCredentialsJSON() string { return paths.fixedCredentialsJSON }
|
||||||
func ConfigINI() string { return paths.configINI }
|
|
||||||
|
|
||||||
// CalculatePaths looks for all external paths and stores them. Tries its best to find any errors. It is safe it to call it multiple times in order to save new paths.
|
// CalculatePaths looks for all external paths and stores them. Tries its best to find any errors. It is safe it to call it multiple times in order to save new paths.
|
||||||
func CalculatePaths() error {
|
func CalculatePaths() error {
|
||||||
@ -38,13 +37,7 @@ func CalculatePaths() error {
|
|||||||
if dir, err := fixedCredentialsPath(); err != nil {
|
if dir, err := fixedCredentialsPath(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
paths.tokensJSON = dir
|
paths.fixedCredentialsJSON = dir
|
||||||
}
|
|
||||||
|
|
||||||
if dir, err := configPath(); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
paths.configINI = dir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -79,11 +72,11 @@ func registrationCredentialsPath() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fixedCredentialsPath() (string, error) {
|
func fixedCredentialsPath() (string, error) {
|
||||||
path, err := filepath.Abs(util.FixedCredentialsPath)
|
var err error
|
||||||
return path, err
|
var path = ""
|
||||||
}
|
|
||||||
|
|
||||||
func configPath() (string, error) {
|
if len(util.FixedCredentialsPath) > 0 {
|
||||||
path, err := filepath.Abs(util.ConfigFilePath)
|
path, err = filepath.Abs(util.FixedCredentialsPath)
|
||||||
|
}
|
||||||
return path, err
|
return path, err
|
||||||
}
|
}
|
||||||
|
6
main.go
6
main.go
@ -179,11 +179,13 @@ Crawl-delay: 5`))
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parseCliArgs()
|
parseCliArgs()
|
||||||
|
|
||||||
|
// It is ok if the path is ""
|
||||||
|
util.ReadConfigFile(util.ConfigFilePath)
|
||||||
|
|
||||||
if err := files.CalculatePaths(); err != nil {
|
if err := files.CalculatePaths(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// It is ok if the path is ""
|
|
||||||
util.ReadConfigFile(files.ConfigINI())
|
|
||||||
|
|
||||||
log.Println("Running MycorrhizaWiki")
|
log.Println("Running MycorrhizaWiki")
|
||||||
if err := os.Chdir(WikiDir); err != nil {
|
if err := os.Chdir(WikiDir); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user