From 6472eeba37e21606e42c66a2b9736493d1fe3754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Sun, 24 Feb 2019 23:11:52 +0100 Subject: [PATCH] added iniflags to support config files --- cmd/DirectoriesToAlbums/main.go | 7 +++---- configs/defaultConfig.ini | 7 +++++++ internal/app/app.go | 25 +++++++++++++++---------- 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 configs/defaultConfig.ini diff --git a/cmd/DirectoriesToAlbums/main.go b/cmd/DirectoriesToAlbums/main.go index 83d9f7f..df173ac 100644 --- a/cmd/DirectoriesToAlbums/main.go +++ b/cmd/DirectoriesToAlbums/main.go @@ -1,19 +1,18 @@ package main import ( - "flag" "github.com/sirupsen/logrus" + "github.com/vharitonsky/iniflags" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/app" "os" ) func main() { - flag.Parse() - rootPath := flag.Arg(0) + iniflags.Parse() InitializeLog() - app.Run(rootPath) + app.Run() } func InitializeLog() { diff --git a/configs/defaultConfig.ini b/configs/defaultConfig.ini new file mode 100644 index 0000000..6ce353f --- /dev/null +++ b/configs/defaultConfig.ini @@ -0,0 +1,7 @@ +allowMissingConfig = false # Don't terminate the app if the ini file cannot be read. +allowUnknownFlags = false # Don't terminate the app if ini file contains unknown flags. +configUpdateInterval = 0s # Update interval for re-reading config file set via -config flag. Zero disables config file re-reading. +imagesRootPath = # This is the images root path that should be mirrored to piwigo. +piwigoPassword = # This is password to the given username. +piwigoUrl = # The root url to your piwigo installation. +piwigoUser = # The username to use during sync. diff --git a/internal/app/app.go b/internal/app/app.go index 945e230..ec0adab 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1,13 +1,21 @@ package app import ( + "flag" "github.com/sirupsen/logrus" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/localFileStructure" "haefelfinger.net/piwigo/DirectoriesToAlbums/internal/pkg/piwigo/authentication" ) -func Run(rootPath string) { - context := configureContext(rootPath) +var ( + imagesRootPath = flag.String("imagesRootPath", "", "This is the images root path that should be mirrored to piwigo.") + piwigoUrl = flag.String("piwigoUrl", "", "The root url to your piwigo installation.") + piwigoUser = flag.String("piwigoUser", "", "The username to use during sync.") + piwigoPassword = flag.String("piwigoPassword", "", "This is password to the given username.") +) + +func Run() { + context := configureContext() loginToPiwigoAndConfigureContext(context) @@ -54,18 +62,15 @@ func UploadImages() { logrus.Warnln("Uploading missing images (NotImplemented)") } -func configureContext(rootPath string) *AppContext { +func configureContext() *AppContext { logrus.Infoln("Preparing application context and configuration") context := new(AppContext) - context.LocalRootPath = rootPath + context.LocalRootPath = *imagesRootPath context.Piwigo = new(authentication.PiwigoContext) - - //TODO: Move this values to configuration files - //No, these are not real credentials :-P - context.Piwigo.Url = "http://pictures.haefelfinger.net/ws.php?format=json" - context.Piwigo.Username = "admin" - context.Piwigo.Password = "asdf" + context.Piwigo.Url = *piwigoUrl + context.Piwigo.Username = *piwigoUser + context.Piwigo.Password = *piwigoPassword return context }