mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-17 01:45:27 +02:00
cmd/ctrld: write default config to home dir when start
This piece was missing in last resolving conflicts.
This commit is contained in:
+4
-1
@@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
v = viper.NewWithOptions(viper.KeyDelimiter("::"))
|
v = viper.NewWithOptions(viper.KeyDelimiter("::"))
|
||||||
defaultConfigWritten = false
|
defaultConfigWritten = false
|
||||||
|
defaultConfigFile = "ctrld.toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var basicModeFlags = []string{"listen", "primary_upstream", "secondary_upstream", "domains", "log", "cache_size"}
|
var basicModeFlags = []string{"listen", "primary_upstream", "secondary_upstream", "domains", "log", "cache_size"}
|
||||||
@@ -161,6 +163,7 @@ func initCLI() {
|
|||||||
cfg.WorkingDirectory = dir
|
cfg.WorkingDirectory = dir
|
||||||
// No config path, generating config in HOME directory.
|
// No config path, generating config in HOME directory.
|
||||||
if configPath == "" && !isNoConfigStart(cmd) && configBase64 == "" {
|
if configPath == "" && !isNoConfigStart(cmd) && configBase64 == "" {
|
||||||
|
defaultConfigFile = filepath.Join(dir, defaultConfigFile)
|
||||||
readConfigFile(true)
|
readConfigFile(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,7 +314,7 @@ func writeConfigFile() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to marshal config to toml: %v", err)
|
log.Fatalf("unable to marshal config to toml: %v", err)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile("ctrld.toml", bs, 0600); err != nil {
|
if err := os.WriteFile(defaultConfigFile, bs, 0600); err != nil {
|
||||||
log.Printf("failed to write config file: %v\n", err)
|
log.Printf("failed to write config file: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user