Skip to content

Commit

Permalink
fix: Only write configuration on change
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-tub committed Mar 26, 2024
1 parent 9c62473 commit 3b560c1
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,22 @@ func (app *SharedFlags) Start(ctx context.Context) error {
// If the client isn't yet initialized
if app.Immich == nil {
conf, err := configuration.Read(app.ConfigurationFile)
confExist := err == nil
if confExist && app.Server == "" && app.Key == "" && app.API == "" {
app.Server = conf.ServerURL
app.Key = conf.APIKey
app.API = conf.APIURL
confExists := err == nil
updateConf := !confExists
// cmd line args take precendence and will update config
if confExists {
if app.Server != "" || app.Key != "" || app.API != "" {
updateConf = true
}
if app.Server == "" {
app.Server = conf.ServerURL
}
if app.Key == "" {
app.Key = conf.APIKey
}
if app.API == "" {
app.API = conf.APIURL
}
}

switch {
Expand All @@ -124,15 +135,17 @@ func (app *SharedFlags) Start(ctx context.Context) error {
return joinedErr
}

// Connection details are saved into the configuration file
conf.ServerURL = app.Server
conf.APIKey = app.Key
conf.APIURL = app.API
err = conf.Write(app.ConfigurationFile)
if err != nil {
err = fmt.Errorf("can't write into the configuration file: %w", err)
joinedErr = errors.Join(joinedErr, err)
return joinedErr
if updateConf {
// Connection details are saved into the configuration file
conf.ServerURL = app.Server
conf.APIKey = app.Key
conf.APIURL = app.API
err = conf.Write(app.ConfigurationFile)
if err != nil {
err = fmt.Errorf("can't write into the configuration file: %w", err)
joinedErr = errors.Join(joinedErr, err)
return joinedErr
}
}

app.Immich, err = immich.NewImmichClient(app.Server, app.Key, app.SkipSSL)
Expand Down

0 comments on commit 3b560c1

Please sign in to comment.