2020-12-18 20:42:12 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-10-06 07:10:50 +02:00
|
|
|
"os"
|
2022-04-03 14:51:58 +02:00
|
|
|
"time"
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
"gopkg.in/yaml.v2"
|
2021-12-09 07:47:23 +01:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2021-12-09 07:47:23 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
2020-12-18 20:42:12 +01:00
|
|
|
)
|
|
|
|
|
2022-04-08 14:22:07 +02:00
|
|
|
// Options hold the global configuration values without further validation or processing.
|
|
|
|
// Application code should retrieve option values via getter functions since they provide
|
|
|
|
// validation and return defaults if a value is empty.
|
2020-12-18 20:42:12 +01:00
|
|
|
type Options struct {
|
2022-04-03 14:51:58 +02:00
|
|
|
Name string `json:"-"`
|
2023-02-21 00:02:44 +01:00
|
|
|
About string `json:"-"`
|
2022-05-20 19:27:33 +02:00
|
|
|
Edition string `json:"-"`
|
2022-04-03 14:51:58 +02:00
|
|
|
Version string `json:"-"`
|
|
|
|
Copyright string `json:"-"`
|
|
|
|
PartnerID string `yaml:"-" json:"-" flag:"partner-id"`
|
2022-07-07 19:12:28 +02:00
|
|
|
AuthMode string `yaml:"AuthMode" json:"-" flag:"auth-mode"`
|
2022-11-22 22:14:34 +01:00
|
|
|
LoginUri string `yaml:"LoginUri" json:"-" flag:"login-uri"`
|
|
|
|
RegisterUri string `yaml:"RegisterUri" json:"-" flag:"register-uri"`
|
|
|
|
PasswordLength int `yaml:"PasswordLength" json:"-" flag:"password-length"`
|
|
|
|
PasswordResetUri string `yaml:"PasswordResetUri" json:"-" flag:"password-reset-uri"`
|
2022-07-07 19:12:28 +02:00
|
|
|
Public bool `yaml:"Public" json:"-" flag:"public"`
|
2022-09-02 21:30:50 +02:00
|
|
|
AdminUser string `yaml:"AdminUser" json:"-" flag:"admin-user"`
|
2022-04-12 20:00:06 +02:00
|
|
|
AdminPassword string `yaml:"AdminPassword" json:"-" flag:"admin-password"`
|
2022-10-25 06:19:56 +02:00
|
|
|
SessionMaxAge int64 `yaml:"SessionMaxAge" json:"-" flag:"session-maxage"`
|
|
|
|
SessionTimeout int64 `yaml:"SessionTimeout" json:"-" flag:"session-timeout"`
|
2022-04-03 14:51:58 +02:00
|
|
|
LogLevel string `yaml:"LogLevel" json:"-" flag:"log-level"`
|
2022-08-31 18:53:04 +02:00
|
|
|
Prod bool `yaml:"Prod" json:"Prod" flag:"prod"`
|
2022-04-03 14:51:58 +02:00
|
|
|
Debug bool `yaml:"Debug" json:"Debug" flag:"debug"`
|
2022-10-11 22:44:11 +02:00
|
|
|
Trace bool `yaml:"Trace" json:"Trace" flag:"trace"`
|
2022-04-03 14:51:58 +02:00
|
|
|
Test bool `yaml:"-" json:"Test,omitempty" flag:"test"`
|
|
|
|
Unsafe bool `yaml:"-" json:"-" flag:"unsafe"`
|
2023-01-15 15:36:20 +01:00
|
|
|
Demo bool `yaml:"-" json:"-" flag:"demo"`
|
2022-04-03 14:51:58 +02:00
|
|
|
Sponsor bool `yaml:"-" json:"-" flag:"sponsor"`
|
|
|
|
ConfigPath string `yaml:"ConfigPath" json:"-" flag:"config-path"`
|
2022-04-13 22:43:49 +02:00
|
|
|
DefaultsYaml string `json:"-" yaml:"-" flag:"defaults-yaml"`
|
2022-04-03 14:51:58 +02:00
|
|
|
OriginalsPath string `yaml:"OriginalsPath" json:"-" flag:"originals-path"`
|
|
|
|
OriginalsLimit int `yaml:"OriginalsLimit" json:"OriginalsLimit" flag:"originals-limit"`
|
|
|
|
ResolutionLimit int `yaml:"ResolutionLimit" json:"ResolutionLimit" flag:"resolution-limit"`
|
|
|
|
StoragePath string `yaml:"StoragePath" json:"-" flag:"storage-path"`
|
|
|
|
SidecarPath string `yaml:"SidecarPath" json:"-" flag:"sidecar-path"`
|
2022-10-17 19:07:38 +02:00
|
|
|
UsersPath string `yaml:"UsersPath" json:"-" flag:"users-path"`
|
2022-04-03 14:51:58 +02:00
|
|
|
BackupPath string `yaml:"BackupPath" json:"-" flag:"backup-path"`
|
2022-04-18 13:55:17 +02:00
|
|
|
CachePath string `yaml:"CachePath" json:"-" flag:"cache-path"`
|
2022-04-07 11:56:44 +02:00
|
|
|
ImportPath string `yaml:"ImportPath" json:"-" flag:"import-path"`
|
2022-09-30 00:42:19 +02:00
|
|
|
ImportDest string `yaml:"ImportDest" json:"-" flag:"import-dest"`
|
2022-04-03 14:51:58 +02:00
|
|
|
AssetsPath string `yaml:"AssetsPath" json:"-" flag:"assets-path"`
|
2022-07-05 23:13:34 +02:00
|
|
|
CustomAssetsPath string `yaml:"-" json:"-" flag:"custom-assets-path"`
|
2022-04-07 11:56:44 +02:00
|
|
|
TempPath string `yaml:"TempPath" json:"-" flag:"temp-path"`
|
2022-04-03 14:51:58 +02:00
|
|
|
Workers int `yaml:"Workers" json:"Workers" flag:"workers"`
|
|
|
|
WakeupInterval time.Duration `yaml:"WakeupInterval" json:"WakeupInterval" flag:"wakeup-interval"`
|
|
|
|
AutoIndex int `yaml:"AutoIndex" json:"AutoIndex" flag:"auto-index"`
|
|
|
|
AutoImport int `yaml:"AutoImport" json:"AutoImport" flag:"auto-import"`
|
2023-01-15 15:36:20 +01:00
|
|
|
ReadOnly bool `yaml:"ReadOnly" json:"ReadOnly" flag:"read-only"`
|
|
|
|
Experimental bool `yaml:"Experimental" json:"Experimental" flag:"experimental"`
|
2022-10-14 12:07:08 +02:00
|
|
|
DisableWebDAV bool `yaml:"DisableWebDAV" json:"DisableWebDAV" flag:"disable-webdav"`
|
2022-04-03 14:51:58 +02:00
|
|
|
DisableBackups bool `yaml:"DisableBackups" json:"DisableBackups" flag:"disable-backups"`
|
|
|
|
DisableSettings bool `yaml:"DisableSettings" json:"-" flag:"disable-settings"`
|
|
|
|
DisablePlaces bool `yaml:"DisablePlaces" json:"DisablePlaces" flag:"disable-places"`
|
|
|
|
DisableTensorFlow bool `yaml:"DisableTensorFlow" json:"DisableTensorFlow" flag:"disable-tensorflow"`
|
|
|
|
DisableFaces bool `yaml:"DisableFaces" json:"DisableFaces" flag:"disable-faces"`
|
|
|
|
DisableClassification bool `yaml:"DisableClassification" json:"DisableClassification" flag:"disable-classification"`
|
|
|
|
DisableFFmpeg bool `yaml:"DisableFFmpeg" json:"DisableFFmpeg" flag:"disable-ffmpeg"`
|
|
|
|
DisableExifTool bool `yaml:"DisableExifTool" json:"DisableExifTool" flag:"disable-exiftool"`
|
2022-04-06 17:46:41 +02:00
|
|
|
DisableSips bool `yaml:"DisableSips" json:"DisableSips" flag:"disable-sips"`
|
2023-02-11 20:18:04 +01:00
|
|
|
DisableDarktable bool `yaml:"DisableDarktable" json:"DisableDarktable" flag:"disable-darktable"`
|
|
|
|
DisableRawTherapee bool `yaml:"DisableRawTherapee" json:"DisableRawTherapee" flag:"disable-rawtherapee"`
|
|
|
|
DisableImageMagick bool `yaml:"DisableImageMagick" json:"DisableImageMagick" flag:"disable-imagemagick"`
|
|
|
|
DisableHeifConvert bool `yaml:"DisableHeifConvert" json:"DisableHeifConvert" flag:"disable-heifconvert"`
|
2023-02-19 16:42:19 +01:00
|
|
|
DisableVectors bool `yaml:"DisableVectors" json:"DisableVectors" flag:"disable-vectors"`
|
2023-02-14 14:43:49 +01:00
|
|
|
DisableJpegXL bool `yaml:"DisableJpegXL" json:"DisableJpegXL" flag:"disable-jpegxl"`
|
2022-04-06 17:46:41 +02:00
|
|
|
DisableRaw bool `yaml:"DisableRaw" json:"DisableRaw" flag:"disable-raw"`
|
2022-04-03 14:51:58 +02:00
|
|
|
RawPresets bool `yaml:"RawPresets" json:"RawPresets" flag:"raw-presets"`
|
2022-04-06 17:46:41 +02:00
|
|
|
ExifBruteForce bool `yaml:"ExifBruteForce" json:"ExifBruteForce" flag:"exif-bruteforce"`
|
2022-04-03 14:51:58 +02:00
|
|
|
DetectNSFW bool `yaml:"DetectNSFW" json:"DetectNSFW" flag:"detect-nsfw"`
|
|
|
|
UploadNSFW bool `yaml:"UploadNSFW" json:"-" flag:"upload-nsfw"`
|
|
|
|
DefaultTheme string `yaml:"DefaultTheme" json:"DefaultTheme" flag:"default-theme"`
|
|
|
|
DefaultLocale string `yaml:"DefaultLocale" json:"DefaultLocale" flag:"default-locale"`
|
|
|
|
AppName string `yaml:"AppName" json:"AppName" flag:"app-name"`
|
|
|
|
AppMode string `yaml:"AppMode" json:"AppMode" flag:"app-mode"`
|
2023-02-10 15:53:01 +01:00
|
|
|
AppIcon string `yaml:"AppIcon" json:"AppIcon" flag:"app-icon"`
|
|
|
|
AppColor string `yaml:"AppColor" json:"AppColor" flag:"app-color"`
|
2022-10-24 12:33:03 +02:00
|
|
|
LegalInfo string `yaml:"LegalInfo" json:"LegalInfo" flag:"legal-info"`
|
|
|
|
LegalUrl string `yaml:"LegalUrl" json:"LegalUrl" flag:"legal-url"`
|
2022-04-22 17:38:40 +02:00
|
|
|
WallpaperUri string `yaml:"WallpaperUri" json:"WallpaperUri" flag:"wallpaper-uri"`
|
2022-04-03 14:51:58 +02:00
|
|
|
CdnUrl string `yaml:"CdnUrl" json:"CdnUrl" flag:"cdn-url"`
|
|
|
|
SiteUrl string `yaml:"SiteUrl" json:"SiteUrl" flag:"site-url"`
|
|
|
|
SiteAuthor string `yaml:"SiteAuthor" json:"SiteAuthor" flag:"site-author"`
|
|
|
|
SiteTitle string `yaml:"SiteTitle" json:"SiteTitle" flag:"site-title"`
|
|
|
|
SiteCaption string `yaml:"SiteCaption" json:"SiteCaption" flag:"site-caption"`
|
|
|
|
SiteDescription string `yaml:"SiteDescription" json:"SiteDescription" flag:"site-description"`
|
|
|
|
SitePreview string `yaml:"SitePreview" json:"SitePreview" flag:"site-preview"`
|
2023-01-19 20:46:27 +01:00
|
|
|
HttpsProxy string `yaml:"HttpsProxy" json:"HttpsProxy" flag:"https-proxy"`
|
|
|
|
HttpsProxyInsecure bool `yaml:"HttpsProxyInsecure" json:"HttpsProxyInsecure" flag:"https-proxy-insecure"`
|
2022-10-12 14:57:33 +02:00
|
|
|
TrustedProxies []string `yaml:"TrustedProxies" json:"-" flag:"trusted-proxy"`
|
2022-11-02 18:55:30 +01:00
|
|
|
ProxyProtoHeaders []string `yaml:"ProxyProtoHeaders" json:"-" flag:"proxy-proto-header"`
|
|
|
|
ProxyProtoHttps []string `yaml:"ProxyProtoHttps" json:"-" flag:"proxy-proto-https"`
|
2022-10-25 06:19:56 +02:00
|
|
|
DisableTLS bool `yaml:"DisableTLS" json:"DisableTLS" flag:"disable-tls"`
|
2023-01-15 15:36:20 +01:00
|
|
|
TLSEmail string `yaml:"TLSEmail" json:"TLSEmail" flag:"tls-email"`
|
2022-10-11 22:44:11 +02:00
|
|
|
TLSCert string `yaml:"TLSCert" json:"TLSCert" flag:"tls-cert"`
|
2022-10-19 05:09:09 +02:00
|
|
|
TLSKey string `yaml:"TLSKey" json:"TLSKey" flag:"tls-key"`
|
2023-01-20 00:37:51 +01:00
|
|
|
HttpMode string `yaml:"HttpMode" json:"-" flag:"http-mode"`
|
|
|
|
HttpCompression string `yaml:"HttpCompression" json:"-" flag:"http-compression"`
|
|
|
|
HttpHost string `yaml:"HttpHost" json:"-" flag:"http-host"`
|
|
|
|
HttpPort int `yaml:"HttpPort" json:"-" flag:"http-port"`
|
2022-04-03 14:51:58 +02:00
|
|
|
DatabaseDriver string `yaml:"DatabaseDriver" json:"-" flag:"database-driver"`
|
|
|
|
DatabaseDsn string `yaml:"DatabaseDsn" json:"-" flag:"database-dsn"`
|
|
|
|
DatabaseName string `yaml:"DatabaseName" json:"-" flag:"database-name"`
|
2022-09-15 07:29:09 +02:00
|
|
|
DatabaseServer string `yaml:"DatabaseServer" json:"-" flag:"database-server"`
|
2022-04-03 14:51:58 +02:00
|
|
|
DatabaseUser string `yaml:"DatabaseUser" json:"-" flag:"database-user"`
|
|
|
|
DatabasePassword string `yaml:"DatabasePassword" json:"-" flag:"database-password"`
|
|
|
|
DatabaseConns int `yaml:"DatabaseConns" json:"-" flag:"database-conns"`
|
|
|
|
DatabaseConnsIdle int `yaml:"DatabaseConnsIdle" json:"-" flag:"database-conns-idle"`
|
|
|
|
SipsBin string `yaml:"SipsBin" json:"-" flag:"sips-bin"`
|
2022-09-15 00:43:08 +02:00
|
|
|
SipsBlacklist string `yaml:"SipsBlacklist" json:"-" flag:"sips-blacklist"`
|
2022-04-03 14:51:58 +02:00
|
|
|
FFmpegBin string `yaml:"FFmpegBin" json:"-" flag:"ffmpeg-bin"`
|
|
|
|
FFmpegEncoder string `yaml:"FFmpegEncoder" json:"FFmpegEncoder" flag:"ffmpeg-encoder"`
|
|
|
|
FFmpegBitrate int `yaml:"FFmpegBitrate" json:"FFmpegBitrate" flag:"ffmpeg-bitrate"`
|
|
|
|
ExifToolBin string `yaml:"ExifToolBin" json:"-" flag:"exiftool-bin"`
|
2023-02-11 20:18:04 +01:00
|
|
|
DarktableBin string `yaml:"DarktableBin" json:"-" flag:"darktable-bin"`
|
|
|
|
DarktableCachePath string `yaml:"DarktableCachePath" json:"-" flag:"darktable-cache-path"`
|
|
|
|
DarktableConfigPath string `yaml:"DarktableConfigPath" json:"-" flag:"darktable-config-path"`
|
|
|
|
DarktableBlacklist string `yaml:"DarktableBlacklist" json:"-" flag:"darktable-blacklist"`
|
|
|
|
RawTherapeeBin string `yaml:"RawTherapeeBin" json:"-" flag:"rawtherapee-bin"`
|
|
|
|
RawTherapeeBlacklist string `yaml:"RawTherapeeBlacklist" json:"-" flag:"rawtherapee-blacklist"`
|
|
|
|
ImageMagickBin string `yaml:"ImageMagickBin" json:"-" flag:"imagemagick-bin"`
|
|
|
|
ImageMagickBlacklist string `yaml:"ImageMagickBlacklist" json:"-" flag:"imagemagick-blacklist"`
|
|
|
|
HeifConvertBin string `yaml:"HeifConvertBin" json:"-" flag:"heifconvert-bin"`
|
|
|
|
RsvgConvertBin string `yaml:"RsvgConvertBin" json:"-" flag:"rsvgconvert-bin"`
|
2022-04-03 14:51:58 +02:00
|
|
|
DownloadToken string `yaml:"DownloadToken" json:"-" flag:"download-token"`
|
|
|
|
PreviewToken string `yaml:"PreviewToken" json:"-" flag:"preview-token"`
|
2022-04-06 18:41:15 +02:00
|
|
|
ThumbColor string `yaml:"ThumbColor" json:"ThumbColor" flag:"thumb-color"`
|
2022-04-07 11:56:44 +02:00
|
|
|
ThumbFilter string `yaml:"ThumbFilter" json:"ThumbFilter" flag:"thumb-filter"`
|
2022-04-03 14:51:58 +02:00
|
|
|
ThumbSize int `yaml:"ThumbSize" json:"ThumbSize" flag:"thumb-size"`
|
|
|
|
ThumbSizeUncached int `yaml:"ThumbSizeUncached" json:"ThumbSizeUncached" flag:"thumb-size-uncached"`
|
2022-04-08 14:45:03 +02:00
|
|
|
ThumbUncached bool `yaml:"ThumbUncached" json:"ThumbUncached" flag:"thumb-uncached"`
|
2022-04-03 14:51:58 +02:00
|
|
|
JpegQuality string `yaml:"JpegQuality" json:"JpegQuality" flag:"jpeg-quality"`
|
2022-04-08 14:45:03 +02:00
|
|
|
JpegSize int `yaml:"JpegSize" json:"JpegSize" flag:"jpeg-size"`
|
2023-02-11 20:18:04 +01:00
|
|
|
PngSize int `yaml:"PngSize" json:"PngSize" flag:"png-size"`
|
2022-04-03 14:51:58 +02:00
|
|
|
FaceSize int `yaml:"-" json:"-" flag:"face-size"`
|
|
|
|
FaceScore float64 `yaml:"-" json:"-" flag:"face-score"`
|
|
|
|
FaceOverlap int `yaml:"-" json:"-" flag:"face-overlap"`
|
|
|
|
FaceClusterSize int `yaml:"-" json:"-" flag:"face-cluster-size"`
|
|
|
|
FaceClusterScore int `yaml:"-" json:"-" flag:"face-cluster-score"`
|
|
|
|
FaceClusterCore int `yaml:"-" json:"-" flag:"face-cluster-core"`
|
|
|
|
FaceClusterDist float64 `yaml:"-" json:"-" flag:"face-cluster-dist"`
|
|
|
|
FaceMatchDist float64 `yaml:"-" json:"-" flag:"face-match-dist"`
|
|
|
|
PIDFilename string `yaml:"PIDFilename" json:"-" flag:"pid-filename"`
|
|
|
|
LogFilename string `yaml:"LogFilename" json:"-" flag:"log-filename"`
|
2023-01-15 15:36:20 +01:00
|
|
|
DetachServer bool `yaml:"DetachServer" json:"-" flag:"detach-server"`
|
2020-12-18 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewOptions creates a new configuration entity by using two methods:
|
|
|
|
//
|
|
|
|
// 1. Load: This will initialize options from a yaml config file.
|
|
|
|
//
|
2022-10-11 22:44:11 +02:00
|
|
|
// 2. ApplyCliContext: Which comes after Load and overrides
|
2022-08-10 16:09:21 +02:00
|
|
|
// any previous options giving an option two override file configs through the CLI.
|
2020-12-18 20:42:12 +01:00
|
|
|
func NewOptions(ctx *cli.Context) *Options {
|
|
|
|
c := &Options{}
|
|
|
|
|
2022-05-20 19:27:33 +02:00
|
|
|
// Has context?
|
2020-12-18 20:42:12 +01:00
|
|
|
if ctx == nil {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:41:18 +02:00
|
|
|
// Set app name from metadata if possible.
|
|
|
|
if s, ok := ctx.App.Metadata["Name"]; ok {
|
2022-05-20 19:27:33 +02:00
|
|
|
c.Name = fmt.Sprintf("%s", s)
|
2022-05-20 15:41:18 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 00:02:44 +01:00
|
|
|
// Set app about from metadata if possible.
|
2022-10-31 12:23:48 +01:00
|
|
|
if s, ok := ctx.App.Metadata["About"]; ok {
|
2023-02-21 00:02:44 +01:00
|
|
|
c.About = fmt.Sprintf("%s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set app edition from metadata if possible.
|
|
|
|
if s, ok := ctx.App.Metadata["Edition"]; ok {
|
2022-05-20 19:27:33 +02:00
|
|
|
c.Edition = fmt.Sprintf("%s", s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set copyright and version information.
|
2020-12-18 20:42:12 +01:00
|
|
|
c.Copyright = ctx.App.Copyright
|
|
|
|
c.Version = ctx.App.Version
|
|
|
|
|
2022-04-13 22:43:49 +02:00
|
|
|
// Load defaults from YAML file?
|
|
|
|
if defaultsYaml := ctx.GlobalString("defaults-yaml"); defaultsYaml == "" {
|
|
|
|
log.Tracef("config: defaults yaml file not specified")
|
|
|
|
} else if c.DefaultsYaml = fs.Abs(defaultsYaml); !fs.FileExists(c.DefaultsYaml) {
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Tracef("config: defaults file %s does not exist", clean.Log(c.DefaultsYaml))
|
2022-04-13 22:43:49 +02:00
|
|
|
} else if err := c.Load(c.DefaultsYaml); err != nil {
|
2022-04-15 09:42:07 +02:00
|
|
|
log.Warnf("config: failed loading defaults from %s (%s)", clean.Log(c.DefaultsYaml), err)
|
2020-12-18 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 22:44:11 +02:00
|
|
|
if err := c.ApplyCliContext(ctx); err != nil {
|
2020-12-18 20:42:12 +01:00
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
// expandFilenames converts path in config to absolute path
|
|
|
|
func (c *Options) expandFilenames() {
|
|
|
|
c.ConfigPath = fs.Abs(c.ConfigPath)
|
|
|
|
c.StoragePath = fs.Abs(c.StoragePath)
|
2022-10-19 20:26:36 +02:00
|
|
|
c.UsersPath = fs.Abs(c.UsersPath)
|
2020-12-18 20:42:12 +01:00
|
|
|
c.BackupPath = fs.Abs(c.BackupPath)
|
|
|
|
c.AssetsPath = fs.Abs(c.AssetsPath)
|
|
|
|
c.CachePath = fs.Abs(c.CachePath)
|
|
|
|
c.OriginalsPath = fs.Abs(c.OriginalsPath)
|
|
|
|
c.ImportPath = fs.Abs(c.ImportPath)
|
|
|
|
c.TempPath = fs.Abs(c.TempPath)
|
|
|
|
c.PIDFilename = fs.Abs(c.PIDFilename)
|
|
|
|
c.LogFilename = fs.Abs(c.LogFilename)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load uses a yaml config file to initiate the configuration entity.
|
|
|
|
func (c *Options) Load(fileName string) error {
|
|
|
|
if fileName == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !fs.FileExists(fileName) {
|
2022-04-13 22:43:49 +02:00
|
|
|
return errors.New(fmt.Sprintf("%s not found", fileName))
|
2020-12-18 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
2021-10-06 07:10:50 +02:00
|
|
|
yamlConfig, err := os.ReadFile(fileName)
|
2020-12-18 20:42:12 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return yaml.Unmarshal(yamlConfig, c)
|
|
|
|
}
|
|
|
|
|
2022-10-11 22:44:11 +02:00
|
|
|
// ApplyCliContext uses options from the CLI to setup configuration overrides
|
2020-12-18 20:42:12 +01:00
|
|
|
// for the entity.
|
2022-10-11 22:44:11 +02:00
|
|
|
func (c *Options) ApplyCliContext(ctx *cli.Context) error {
|
|
|
|
return ApplyCliContext(c, ctx)
|
2020-12-18 20:42:12 +01:00
|
|
|
}
|