Fix bugs
This commit is contained in:
parent
080c1a3d06
commit
bc35aece9b
3 changed files with 9 additions and 3 deletions
|
@ -27,11 +27,17 @@ func LoadConfig(path string) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateConfig(path string, cfg *Config) {
|
func CreateConfig(path string, cfg *Config) {
|
||||||
|
err := os.MkdirAll(filepath.Dir(path), 0755)
|
||||||
|
Check(err, "Failed to make directories for %q, err: %s", path, err)
|
||||||
conf, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
conf, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
Check(err, "Couldn't open %q, err: %s", path, err)
|
Check(err, "Couldn't open %q, err: %s", path, err)
|
||||||
encoder := toml.NewEncoder(conf)
|
encoder := toml.NewEncoder(conf)
|
||||||
log.Printf("ZeroooConfig: %#v", cfg)
|
log.Printf("ZeroooConfig: %#v", cfg)
|
||||||
err = encoder.Encode(cfg)
|
err = encoder.Encode(cfg)
|
||||||
|
if cfg.Zerooo.Location == "" {
|
||||||
|
cfg.Zerooo.Location = "/etc/zerooo"
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.Zerooo.Location[0] != '/' {
|
if cfg.Zerooo.Location[0] != '/' {
|
||||||
cfg.Zerooo.Location = filepath.Join(filepath.Dir(path), cfg.Zerooo.Location)
|
cfg.Zerooo.Location = filepath.Join(filepath.Dir(path), cfg.Zerooo.Location)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[zerooo]
|
[zerooo]
|
||||||
location = "/etc/zerooo"
|
location = "/etc/zerooo"
|
||||||
endpoint = "https://zer.ooo"
|
endpoint = "https://zer.ooo"
|
||||||
|
|
|
@ -26,7 +26,7 @@ var initCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.Flag("location").Changed) {
|
if (cmd.Flag("location").Changed) {
|
||||||
if location[0] != '/' {
|
if len(location) > 0 && location[0] != '/' {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
service.Check(err, "Can't get current working directory, err: %s", err)
|
service.Check(err, "Can't get current working directory, err: %s", err)
|
||||||
location = filepath.Join(cwd, location)
|
location = filepath.Join(cwd, location)
|
||||||
|
|
Loading…
Reference in a new issue