Skip to content

Conversation

markferry
Copy link

@markferry markferry commented Sep 11, 2025

Fixes #201

This moves state files from os.UserConfigDir to os.UserCacheDir by default.

The config file remains in the original location.

  • add --config flag

    • can specify a custom config file independent of state (cache) files
    • default config remains at os.UserConfigDir()
  • add --cache flag

    • rename config_dir flag to cache
    • default state moves to os.UserCacheDir()
    • provide backwards compatibility for config_dir

To use the old behaviour:

go run ./cmd/daemon --cache $XDG_CONFIG_HOME/go-librespot

@markferry
Copy link
Author

gofmt demands horizontal alignment? That's... insane.

defaultConfigPath := filepath.Join(userConfigDir, "go-librespot", "config.yaml")
f.StringVar(&cfg.ConfigPath, "config", defaultConfigPath, "the configuration file")

userCacheDir, err := os.UserCacheDir()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be XDG_STATE_HOME rather than XDG_CACHE_HOME. Eventually there'll be proper cache too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be ideal, yes, but os pkg does not yet support it.

Comment on lines +419 to +430
// backwards compatibility for config_dir flag
func aliasNormalizeFunc(f *flag.FlagSet, name string) flag.NormalizedName {
switch name {
case "config_dir":
name = "cache"
break
}
return flag.NormalizedName(name)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to explictely keep the config_dir option, for backward compatibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I keep it should it follow UserConfigDir or UserCacheDir semantics?

If the former then we have a breaking change for existing deployments of go-librespot.

Either way I take your point - I'll find a way to make it more explicit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making use of pflag.MarkDeprecated? (And then unhiding the flag, because pflag autohides it)

$ go run ./cmd/daemon -help
  --cache string        the cache directory (default "/var/cache/go-librespot")
  --config string       the configuration file (default "/etc/go-librespot/config.yaml")
  --config_dir string   old config directory  (default "/var/cache/go-librespot") (DEPRECATED: has been renamed --cache)

It doesn't improve things, IMO.

Given go-librespot is pre v1.0 I'd much rather see config_dir dropped with prejudice. Not having underscores in flags is an added bonus.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guidcruncher, your view?

@markferry markferry force-pushed the fix-201-separate-config branch from 3f0db8a to 2527809 Compare September 15, 2025 17:30
@guidcruncher
Copy link

guidcruncher commented Sep 15, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request :Seperate state files from config
3 participants