photoprism/config.go

76 lines
1.7 KiB
Go
Raw Normal View History

2018-02-04 17:34:07 +01:00
package photoprism
import (
"github.com/kylelemons/go-gypsy/yaml"
"github.com/urfave/cli"
)
type Config struct {
ConfigFile string
DarktableCli string
OriginalsPath string
ThumbnailsPath string
ImportPath string
ExportPath string
}
func NewConfig() *Config {
return &Config{}
}
func (c *Config) SetValuesFromFile(fileName string) error {
2018-02-04 17:34:07 +01:00
yamlConfig, err := yaml.ReadFile(fileName)
if err != nil {
return err
}
c.ConfigFile = fileName
2018-02-04 17:34:07 +01:00
if OriginalsPath, err := yamlConfig.Get("originals-path"); err == nil {
2018-02-27 19:51:52 +01:00
c.OriginalsPath = GetExpandedFilename(OriginalsPath)
2018-02-04 17:34:07 +01:00
}
if ThumbnailsPath, err := yamlConfig.Get("thumbnails-path"); err == nil {
2018-02-27 19:51:52 +01:00
c.ThumbnailsPath = GetExpandedFilename(ThumbnailsPath)
2018-02-04 17:34:07 +01:00
}
if ImportPath, err := yamlConfig.Get("import-path"); err == nil {
2018-02-27 19:51:52 +01:00
c.ImportPath = GetExpandedFilename(ImportPath)
2018-02-04 17:34:07 +01:00
}
if ExportPath, err := yamlConfig.Get("export-path"); err == nil {
2018-02-27 19:51:52 +01:00
c.ExportPath = GetExpandedFilename(ExportPath)
2018-02-04 17:34:07 +01:00
}
if DarktableCli, err := yamlConfig.Get("darktable-cli"); err == nil {
2018-02-27 19:51:52 +01:00
c.DarktableCli = GetExpandedFilename(DarktableCli)
2018-02-04 17:34:07 +01:00
}
return nil
}
func (c *Config) SetValuesFromCliContext(context *cli.Context) error {
if context.IsSet("originals-path") {
2018-02-27 19:51:52 +01:00
c.OriginalsPath = GetExpandedFilename(context.String("originals-path"))
2018-02-04 17:34:07 +01:00
}
if context.IsSet("thumbnails-path") {
2018-02-27 19:51:52 +01:00
c.ThumbnailsPath = GetExpandedFilename(context.String("thumbnails-path"))
2018-02-04 17:34:07 +01:00
}
if context.IsSet("import-path") {
2018-02-27 19:51:52 +01:00
c.ImportPath = GetExpandedFilename(context.String("import-path"))
2018-02-04 17:34:07 +01:00
}
if context.IsSet("export-path") {
2018-02-27 19:51:52 +01:00
c.ExportPath = GetExpandedFilename(context.String("export-path"))
2018-02-04 17:34:07 +01:00
}
if context.IsSet("darktable-cli") {
2018-02-27 19:51:52 +01:00
c.DarktableCli = GetExpandedFilename(context.String("darktable-cli"))
2018-02-04 17:34:07 +01:00
}
return nil
}