2018-01-03 07:04:48 +01:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package cli // import "miniflux.app/cli"
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/config"
|
|
|
|
"miniflux.app/daemon"
|
|
|
|
"miniflux.app/database"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/storage"
|
|
|
|
"miniflux.app/version"
|
2018-01-03 07:04:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Parse parses command line arguments.
|
|
|
|
func Parse() {
|
|
|
|
flagInfo := flag.Bool("info", false, "Show application information")
|
|
|
|
flagVersion := flag.Bool("version", false, "Show application version")
|
|
|
|
flagMigrate := flag.Bool("migrate", false, "Migrate database schema")
|
|
|
|
flagFlushSessions := flag.Bool("flush-sessions", false, "Flush all sessions (disconnect users)")
|
|
|
|
flagCreateAdmin := flag.Bool("create-admin", false, "Create admin user")
|
2018-01-03 07:18:24 +01:00
|
|
|
flagResetPassword := flag.Bool("reset-password", false, "Reset user password")
|
2018-06-30 23:22:45 +02:00
|
|
|
flagResetFeedErrors := flag.Bool("reset-feed-errors", false, "Clear all feed errors for all users")
|
2018-01-30 05:34:00 +01:00
|
|
|
flagDebugMode := flag.Bool("debug", false, "Enable debug mode (more verbose output)")
|
2018-01-03 07:04:48 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
cfg := config.NewConfig()
|
2018-02-24 03:26:34 +01:00
|
|
|
|
|
|
|
if *flagDebugMode || cfg.HasDebugMode() {
|
|
|
|
logger.EnableDebug()
|
|
|
|
}
|
|
|
|
|
2018-08-02 05:28:45 +02:00
|
|
|
db, err := database.NewConnectionPool(cfg.DatabaseURL(), cfg.DatabaseMinConns(), cfg.DatabaseMaxConns())
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal("Unable to connect to the database: %v", err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
store := storage.NewStorage(db)
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
if *flagInfo {
|
|
|
|
info()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *flagVersion {
|
|
|
|
fmt.Println(version.Version)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *flagMigrate {
|
2018-08-02 05:28:45 +02:00
|
|
|
database.Migrate(db)
|
2018-01-03 07:04:48 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-30 23:22:45 +02:00
|
|
|
if *flagResetFeedErrors {
|
|
|
|
store.ResetFeedErrors()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
if *flagFlushSessions {
|
|
|
|
flushSessions(store)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *flagCreateAdmin {
|
|
|
|
createAdmin(store)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-03 07:18:24 +01:00
|
|
|
if *flagResetPassword {
|
|
|
|
resetPassword(store)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-16 05:27:10 +02:00
|
|
|
// Run migrations and start the deamon.
|
|
|
|
if cfg.RunMigrations() {
|
2018-08-02 05:28:45 +02:00
|
|
|
database.Migrate(db)
|
2018-04-16 05:27:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create admin user and start the deamon.
|
|
|
|
if cfg.CreateAdmin() {
|
|
|
|
createAdmin(store)
|
|
|
|
}
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
daemon.Run(cfg, store)
|
|
|
|
}
|