Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: override configuration from flags only if set #865

Merged
merged 6 commits into from
Mar 30, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"context"
"strings"

Expand Down Expand Up @@ -54,13 +55,25 @@ func newServerCommandHandler() func(cmd *cobra.Command, args []string) {
rootPath += "/"
}

// Override configuration from flags
cfg.Http.Port = port
cfg.Http.Address = address + ":"
cfg.Http.RootPath = rootPath
cfg.Http.AccessLog = accessLog
cfg.Http.ServeWebUI = serveWebUI
cfg.Http.SecretKey = secretKey
// Override configuration from flags if needed
if cmd.Flags().Changed("port") && cfg.Http.Port != port {
cfg.Http.Port = port
}
if cmd.Flags().Changed("address") && cfg.Http.Address != address+":" {
cfg.Http.Address = address + ":"
}
if cmd.Flags().Changed("webroot") && cfg.Http.RootPath != rootPath {
cfg.Http.RootPath = rootPath
}
if cmd.Flags().Changed("access-log") && cfg.Http.AccessLog != accessLog {
cfg.Http.AccessLog = accessLog
}
if cmd.Flags().Changed("serve-web-ui") && cfg.Http.ServeWebUI != serveWebUI {
cfg.Http.ServeWebUI = serveWebUI
}
if cmd.Flags().Changed("secret-key") && !bytes.Equal(cfg.Http.SecretKey, secretKey) {
cfg.Http.SecretKey = secretKey
}

dependencies.Log.Infof("Starting Shiori v%s", model.BuildVersion)

Expand Down
Loading