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/database"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/storage"
|
|
|
|
"miniflux.app/version"
|
2018-01-03 07:04:48 +01:00
|
|
|
)
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
const (
|
2018-11-12 00:32:48 +01:00
|
|
|
flagInfoHelp = "Show application information"
|
|
|
|
flagVersionHelp = "Show application version"
|
|
|
|
flagMigrateHelp = "Run SQL migrations"
|
|
|
|
flagFlsuhSessionsHelp = "Flush all sessions (disconnect users)"
|
|
|
|
flagCreateAdminHelp = "Create admin user"
|
|
|
|
flagResetPasswordHelp = "Reset user password"
|
2018-10-09 06:00:00 +02:00
|
|
|
flagResetFeedErrorsHelp = "Clear all feed errors for all users"
|
2018-11-12 00:32:48 +01:00
|
|
|
flagDebugModeHelp = "Show debug logs"
|
2018-10-09 06:00:00 +02:00
|
|
|
)
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
// Parse parses command line arguments.
|
|
|
|
func Parse() {
|
2018-10-09 06:00:00 +02:00
|
|
|
var (
|
2018-11-12 00:32:48 +01:00
|
|
|
flagInfo bool
|
|
|
|
flagVersion bool
|
|
|
|
flagMigrate bool
|
|
|
|
flagFlushSessions bool
|
|
|
|
flagCreateAdmin bool
|
|
|
|
flagResetPassword bool
|
2018-10-09 06:00:00 +02:00
|
|
|
flagResetFeedErrors bool
|
2018-11-12 00:32:48 +01:00
|
|
|
flagDebugMode bool
|
2018-10-09 06:00:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
|
|
|
|
flag.BoolVar(&flagInfo, "i", false, flagInfoHelp)
|
|
|
|
flag.BoolVar(&flagVersion, "version", false, flagVersionHelp)
|
|
|
|
flag.BoolVar(&flagVersion, "v", false, flagVersionHelp)
|
|
|
|
flag.BoolVar(&flagMigrate, "migrate", false, flagMigrateHelp)
|
|
|
|
flag.BoolVar(&flagFlushSessions, "flush-sessions", false, flagFlsuhSessionsHelp)
|
|
|
|
flag.BoolVar(&flagCreateAdmin, "create-admin", false, flagCreateAdminHelp)
|
|
|
|
flag.BoolVar(&flagResetPassword, "reset-password", false, flagResetPasswordHelp)
|
|
|
|
flag.BoolVar(&flagResetFeedErrors, "reset-feed-errors", false, flagResetFeedErrorsHelp)
|
2018-11-12 00:32:48 +01:00
|
|
|
flag.BoolVar(&flagDebugMode, "debug", false, flagDebugModeHelp)
|
2018-01-03 07:04:48 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
cfg := config.NewConfig()
|
2018-02-24 03:26:34 +01:00
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagDebugMode || cfg.HasDebugMode() {
|
2018-02-24 03:26:34 +01:00
|
|
|
logger.EnableDebug()
|
|
|
|
}
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagInfo {
|
2018-01-03 07:04:48 +01:00
|
|
|
info()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagVersion {
|
2018-01-03 07:04:48 +01:00
|
|
|
fmt.Println(version.Version)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-03 06:19:09 +01: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()
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagMigrate {
|
2018-08-02 05:28:45 +02:00
|
|
|
database.Migrate(db)
|
2018-01-03 07:04:48 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-03 06:19:09 +01:00
|
|
|
store := storage.NewStorage(db)
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagResetFeedErrors {
|
2018-06-30 23:22:45 +02:00
|
|
|
store.ResetFeedErrors()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagFlushSessions {
|
2018-01-03 07:04:48 +01:00
|
|
|
flushSessions(store)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagCreateAdmin {
|
2018-01-03 07:04:48 +01:00
|
|
|
createAdmin(store)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-09 06:00:00 +02:00
|
|
|
if flagResetPassword {
|
2018-01-03 07:18:24 +01:00
|
|
|
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-11-12 00:32:48 +01:00
|
|
|
startDaemon(cfg, store)
|
2018-01-03 07:04:48 +01:00
|
|
|
}
|