Store config in user state and clean old release notes

This commit is contained in:
Mikhail Chusavitin
2026-02-04 11:21:48 +03:00
parent e2800b06f9
commit 4509e93864
5 changed files with 80 additions and 121 deletions

View File

@@ -41,7 +41,7 @@ import (
var Version = "dev"
func main() {
configPath := flag.String("config", "config.yaml", "path to config file (optional, for server settings)")
configPath := flag.String("config", "", "path to config file (default: user state dir or QFS_CONFIG_PATH)")
localDBPath := flag.String("localdb", "", "path to local SQLite database (default: user state dir or QFS_DB_PATH)")
migrate := flag.Bool("migrate", false, "run database migrations")
version := flag.Bool("version", false, "show version information")
@@ -56,12 +56,28 @@ func main() {
exePath, _ := os.Executable()
slog.Info("starting qfs", "version", Version, "executable", exePath)
resolvedConfigPath, err := appstate.ResolveConfigPath(*configPath)
if err != nil {
slog.Error("failed to resolve config path", "error", err)
os.Exit(1)
}
resolvedLocalDBPath, err := appstate.ResolveDBPath(*localDBPath)
if err != nil {
slog.Error("failed to resolve local database path", "error", err)
os.Exit(1)
}
// Migrate legacy project-local config path to the user state directory when using defaults.
if *configPath == "" && os.Getenv("QFS_CONFIG_PATH") == "" {
migratedFrom, migrateErr := appstate.MigrateLegacyFile(resolvedConfigPath, []string{"config.yaml"})
if migrateErr != nil {
slog.Warn("failed to migrate legacy config file", "error", migrateErr)
} else if migratedFrom != "" {
slog.Info("migrated legacy config file", "from", migratedFrom, "to", resolvedConfigPath)
}
}
// Migrate legacy project-local DB path to the user state directory when using defaults.
if *localDBPath == "" && os.Getenv("QFS_DB_PATH") == "" {
legacyPaths := []string{
@@ -91,18 +107,19 @@ func main() {
}
// Load config for server settings (optional)
cfg, err := config.Load(*configPath)
cfg, err := config.Load(resolvedConfigPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// Use defaults if config file doesn't exist
slog.Info("config file not found, using defaults", "path", *configPath)
slog.Info("config file not found, using defaults", "path", resolvedConfigPath)
cfg = &config.Config{}
} else {
slog.Error("failed to load config", "path", *configPath, "error", err)
slog.Error("failed to load config", "path", resolvedConfigPath, "error", err)
os.Exit(1)
}
}
setConfigDefaults(cfg)
slog.Info("resolved runtime files", "config_path", resolvedConfigPath, "localdb_path", resolvedLocalDBPath)
setupLogger(cfg.Logging)