add lucy config.
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Remote string `yaml:"remote"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig() (*Config, error) {
|
||||||
|
homedir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(path.Join(homedir, ".config/lucy.yaml"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := Config{}
|
||||||
|
err = yaml.NewDecoder(f).Decode(&cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &cfg, nil
|
||||||
|
}
|
||||||
+7
-1
@@ -11,7 +11,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := client.Client{APIRoot: "http://10.24.4.1:8000"}
|
cfg, err := loadConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Config at $HOME/.config/lucy.yaml failed:", err)
|
||||||
|
cfg = &Config{Remote: "http://localhost:8000"}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := client.Client{APIRoot: cfg.Remote}
|
||||||
cmd := parseCommand(os.Args[1:])
|
cmd := parseCommand(os.Args[1:])
|
||||||
|
|
||||||
switch cmd.Name {
|
switch cmd.Name {
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ require (
|
|||||||
github.com/pressly/goose v2.7.0+incompatible
|
github.com/pressly/goose v2.7.0+incompatible
|
||||||
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 // indirect
|
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
|
gopkg.in/yaml.v2 v2.2.8
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user