cli.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package cli
  5. import (
  6. "flag"
  7. "fmt"
  8. "github.com/miniflux/miniflux/config"
  9. "github.com/miniflux/miniflux/daemon"
  10. "github.com/miniflux/miniflux/logger"
  11. "github.com/miniflux/miniflux/storage"
  12. "github.com/miniflux/miniflux/version"
  13. )
  14. // Parse parses command line arguments.
  15. func Parse() {
  16. flagInfo := flag.Bool("info", false, "Show application information")
  17. flagVersion := flag.Bool("version", false, "Show application version")
  18. flagMigrate := flag.Bool("migrate", false, "Migrate database schema")
  19. flagFlushSessions := flag.Bool("flush-sessions", false, "Flush all sessions (disconnect users)")
  20. flagCreateAdmin := flag.Bool("create-admin", false, "Create admin user")
  21. flagResetPassword := flag.Bool("reset-password", false, "Reset user password")
  22. flagResetFeedErrors := flag.Bool("reset-feed-errors", false, "Clear all feed errors for all users")
  23. flagDebugMode := flag.Bool("debug", false, "Enable debug mode (more verbose output)")
  24. flag.Parse()
  25. cfg := config.NewConfig()
  26. if *flagDebugMode || cfg.HasDebugMode() {
  27. logger.EnableDebug()
  28. }
  29. store := storage.NewStorage(
  30. cfg.DatabaseURL(),
  31. cfg.DatabaseMaxConnections(),
  32. )
  33. if *flagInfo {
  34. info()
  35. return
  36. }
  37. if *flagVersion {
  38. fmt.Println(version.Version)
  39. return
  40. }
  41. if *flagMigrate {
  42. store.Migrate()
  43. return
  44. }
  45. if *flagResetFeedErrors {
  46. store.ResetFeedErrors()
  47. return
  48. }
  49. if *flagFlushSessions {
  50. flushSessions(store)
  51. return
  52. }
  53. if *flagCreateAdmin {
  54. createAdmin(store)
  55. return
  56. }
  57. if *flagResetPassword {
  58. resetPassword(store)
  59. return
  60. }
  61. // Run migrations and start the deamon.
  62. if cfg.RunMigrations() {
  63. store.Migrate()
  64. }
  65. // Create admin user and start the deamon.
  66. if cfg.CreateAdmin() {
  67. createAdmin(store)
  68. }
  69. daemon.Run(cfg, store)
  70. }