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 }