clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

add config flag and db_path config value

Dami committed c81e86e
commit
c81e86e3ff5b50d8635993ce3a7df0cfaca2cbb7
parent
e6ca1238f49c5f1f807a83d2d3b3b3f8e2cd9550
author
Dami <dami.etoile@gmail.com>
5 files changed, +31 -15
Mcmd/continue.go4++--
Mcmd/list.go3++-
Mcmd/new.go6+++---
Mcmd/root.go20+++++++++++++-------
Mconfig/config.go13+++++++++++--
M cmd/continue.go +2 -2
M cmd/list.go +2 -1
M cmd/new.go +3 -3
M cmd/root.go +13 -7
@@ -22,9 +22,10 @@ import (
2222 var Version = "dev"2323 2424 var (25- flagNew string26- flagContinue string27- flagTheme string25+ flagNew string26+ flagContinue string27+ flagTheme string28+ flagConfigPath string2829 // flagSetSeed is declared in new.go and shared across root and new commands.2930 )3031
@@ -35,7 +36,7 @@ var RootCmd = &cobra.Command{
3536 Short: "A terminal-based puzzle game framework",3637 Long: "PuzzleTea is a terminal-based puzzle game framework featuring Nonogram, Nurikabe, Sudoku, Word Search, Hashiwokakero, and Lights Out.",3738 RunE: func(cmd *cobra.Command, args []string) error {38- cfg := loadConfig()39+ cfg := loadConfig(flagConfigPath)3940 4041 if flagSetSeed != "" {4142 if flagNew != "" || flagContinue != "" {
@@ -56,7 +57,7 @@ var RootCmd = &cobra.Command{
5657 return continueGame(flagContinue, cfg)5758 }5859 // Default: launch TUI menu.59- s, err := store.Open(store.DefaultDBPath())60+ s, err := store.Open(cfg.DBPath)6061 if err != nil {6162 return err6263 }
@@ -72,6 +73,7 @@ func init() {
7273 RootCmd.Flags().StringVar(&flagNew, "new", "", "start a new game (game:mode)")7374 RootCmd.Flags().StringVar(&flagContinue, "continue", "", "resume a saved game by name")7475 RootCmd.Flags().StringVar(&flagSetSeed, "set-seed", "", "seed string for deterministic puzzle selection and generation")76+ RootCmd.PersistentFlags().StringVar(&flagConfigPath, "config", "", "path to config file (default: ~/.puzzletea/config.json)")7577 RootCmd.PersistentFlags().StringVar(&flagTheme, "theme", "", "color theme name (overrides config)")7678 7779 RootCmd.AddCommand(newCmd, continueCmd, listCmd, exportPDFCmd)
@@ -79,8 +81,12 @@ func init() {
7981 8082 // loadConfig reads the config file and applies the active theme. The --theme8183 // flag takes precedence over the persisted setting.82-func loadConfig() *config.Config {83- cfg, err := config.Load(config.DefaultPath())84+func loadConfig(configPath string) *config.Config {85+ if configPath == "" {86+ configPath = config.DefaultPath()87+ }88+89+ cfg, err := config.Load(configPath)8490 if err != nil {8591 log.Printf("warning: %v (using defaults)", err)8692 cfg = config.Default()
M config/config.go +11 -2