Fixed bugs with --config flag

This commit is contained in:
2026-06-05 21:48:25 -05:00
parent 17117e2376
commit 53b9f30d50
4 changed files with 37 additions and 18 deletions

View File

@@ -6,7 +6,6 @@ import (
"net/http"
"os"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
@@ -25,12 +24,14 @@ type InstanceStatusResponse struct {
type DaemonServer struct {
cfg *AppConfig
configPath string
procManager *ProcessManager
}
func StartDaemon(cfg *AppConfig) error {
func StartDaemon(cfg *AppConfig, configPath string) error {
ds := &DaemonServer{
cfg: cfg,
configPath: configPath,
procManager: NewProcessManager(),
}
@@ -173,10 +174,16 @@ func (ds *DaemonServer) handleCreate(w http.ResponseWriter, r *http.Request) {
ds.cfg.Instances[name] = options
home, _ := os.UserHomeDir()
configPath := filepath.Join(home, ".config", "vs-manager", "config.json")
data, _ := json.MarshalIndent(ds.cfg, "", " ")
_ = os.WriteFile(configPath, data, 0644)
data, err := json.MarshalIndent(ds.cfg, "", " ")
if err != nil {
http.Error(w, fmt.Sprintf("Failed processing profile adjustments: %v", err), http.StatusInternalServerError)
return
}
if err := os.WriteFile(ds.configPath, data, 0644); err != nil {
http.Error(w, fmt.Sprintf("Failed saving configuration adjustments to disk: %v", err), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "Successfully created and stored profile for instance %s", name)
@@ -200,7 +207,7 @@ func (ds *DaemonServer) handleStart(w http.ResponseWriter, r *http.Request) {
return
}
instanceConfigPath := filepath.Join(ds.cfg.Storage.InstancesDir, name, "serverconfig.json")
instanceConfigPath := ds.configPath
err := SyncInstanceConfig(options.Version, instanceConfigPath, options, ds.cfg)
if err != nil {
http.Error(w, "Failed to sync config: "+err.Error(), http.StatusInternalServerError)