Skip to content

Commit

Permalink
Allows to reload config file after program start
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Nov 25, 2024
1 parent a34deed commit 79f4c18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/apps/chifra/internal/config/handle_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// HandleDump dumps a config to the screen
func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error {
config.ReloadConfig()
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
config := *config.GetRootConfig()
s := types.Config{
Expand Down
10 changes: 8 additions & 2 deletions src/apps/chifra/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func GetRootConfig() *configtypes.Config {
return &trueBlocksConfig
}

// ReloadConfig clears the config cache so that the next time ReadToml is
// called the config will reload
func ReloadConfig() {
configLoaded = false
}

// PathToConfigFile returns the path where to find the configuration file
func PathToConfigFile() string {
configFolder := PathToRootConfig()
Expand Down Expand Up @@ -186,10 +192,10 @@ func pathFromXDG(envVar string) (string, error) {
return "", nil // it's okay if it's empty
}

absXDGPath, err := filepath.Abs(xdg);
absXDGPath, err := filepath.Abs(xdg)
if err != nil {
return "", usage.Usage("The {0} value ({1}), could not be interpreted as an absolute path.", envVar, xdg)
}
}

if _, err := os.Stat(absXDGPath); err != nil {
return "", usage.Usage("The {0} folder ({1}) must exist.", envVar, absXDGPath)
Expand Down

0 comments on commit 79f4c18

Please sign in to comment.