Skip to content

Commit 8c2990c

Browse files
committed
move persistance variable from env to flags
1 parent 0558954 commit 8c2990c

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/config/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type Config struct {
1818
DiscoveryCfg DiscoveryConfig
1919
ClientCfg ClientConfig
2020
Flags Flags
21-
Persist bool `env:"PERSIST" env-default:"true"`
21+
PersistENV bool `env:"PERSIST" env-default:"true"`
22+
Persist bool
2223
System string `env:"EXPLO_SYSTEM"`
2324
Debug bool `env:"DEBUG" env-default:"false"`
2425
LogLevel string `env:"LOG_LEVEL" env-default:"WARN"`
@@ -29,6 +30,8 @@ type Flags struct {
2930
Playlist string
3031
DownloadMode string
3132
ExcludeLocal bool
33+
Persist bool
34+
PersistSet bool
3235
}
3336

3437
type ClientConfig struct {
@@ -162,6 +165,13 @@ func (cfg *Config) HandleDeprecation() { //
162165
slog.Warn("'DEBUG' variable is deprecated, please use LOG_LEVEL=DEBUG instead")
163166
cfg.LogLevel = "DEBUG"
164167
}
168+
if !cfg.PersistENV {
169+
slog.Warn("'PERSIST' variable is deprecated, use --persist flag instead")
170+
}
171+
172+
if !cfg.Persist && !cfg.DownloadCfg.UseSubDir {
173+
slog.Warn("Deleting tracks requires 'USE_SUBDIRECTORY' to be true")
174+
}
165175
}
166176

167177
func (cfg *Config) GetPlaylistName() { // Generate playlist name and description

src/config/flags.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ func (cfg *Config) GetFlags() error {
1616
var configPath string
1717
var playlist string
1818
var downloadMode string
19-
var ExcludeLocal bool
19+
var excludeLocal bool
20+
var persist bool
2021
// Long flags
2122
flag.StringVarP(&configPath, "config", "c", ".env", "Path of the configuration file")
2223
flag.StringVarP(&playlist, "playlist", "p", "weekly-exploration", "Playlist where to get tracks. Supported: weekly-exploration, weekly-jams, daily-jams")
2324
flag.StringVarP(&downloadMode, "download-mode", "d", "normal", "Download mode: 'normal' (download only when track is not found locally), 'skip' (skip downloading, only use tracks already found locally), 'force' (always download, don't check for local tracks)")
24-
flag.BoolVarP(&ExcludeLocal, "exclude-local", "e", false, "Exclude locally found tracks from the imported playlist")
25+
flag.BoolVarP(&excludeLocal, "exclude-local", "e", false, "Exclude locally found tracks from the imported playlist")
26+
flag.BoolVar(&persist, "persist", true, "Keep playlists between generations")
27+
persistSet := flag.Lookup("persist").Changed
2528

2629
flag.Parse()
2730

@@ -40,14 +43,25 @@ func (cfg *Config) GetFlags() error {
4043
cfg.Flags.CfgPath = configPath
4144
cfg.Flags.Playlist = playlist
4245
cfg.Flags.DownloadMode = downloadMode
43-
cfg.Flags.ExcludeLocal = ExcludeLocal
46+
cfg.Flags.ExcludeLocal = excludeLocal
47+
cfg.Flags.Persist = persist
48+
49+
// for deprecation purposes (can be removed at a later date)
50+
cfg.Flags.PersistSet = persistSet
51+
4452
cfg.mergeFlags()
4553
return nil
4654
}
4755

4856
func (cfg *Config) mergeFlags() {
4957
cfg.DiscoveryCfg.Listenbrainz.ImportPlaylist = cfg.Flags.Playlist
5058
cfg.DownloadCfg.ExcludeLocal = cfg.Flags.ExcludeLocal
59+
60+
if cfg.Flags.PersistSet {
61+
cfg.Persist = cfg.Flags.Persist
62+
} else {
63+
cfg.Persist = cfg.PersistENV
64+
}
5165
}
5266

5367
func contains(valid []string, val string) bool {

src/main/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
slog.Error(err.Error())
5959
os.Exit(1)
6060
}
61-
if !cfg.Persist {
61+
if !cfg.Persist && cfg.DownloadCfg.UseSubDir {
6262
err := client.DeletePlaylist()
6363
if err != nil {
6464
slog.Warn(err.Error())

0 commit comments

Comments
 (0)