cli.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/logger"
  9. "github.com/miniflux/miniflux/config"
  10. "github.com/miniflux/miniflux/daemon"
  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. flagDebugMode := flag.Bool("debug", false, "Enable debug mode (more verbose output)")
  23. flag.Parse()
  24. cfg := config.NewConfig()
  25. if *flagDebugMode || cfg.HasDebugMode() {
  26. logger.EnableDebug()
  27. }
  28. store := storage.NewStorage(
  29. cfg.DatabaseURL(),
  30. cfg.DatabaseMaxConnections(),
  31. )
  32. if *flagInfo {
  33. info()
  34. return
  35. }
  36. if *flagVersion {
  37. fmt.Println(version.Version)
  38. return
  39. }
  40. if *flagMigrate {
  41. store.Migrate()
  42. return
  43. }
  44. if *flagFlushSessions {
  45. flushSessions(store)
  46. return
  47. }
  48. if *flagCreateAdmin {
  49. createAdmin(store)
  50. return
  51. }
  52. if *flagResetPassword {
  53. resetPassword(store)
  54. return
  55. }
  56. daemon.Run(cfg, store)
  57. }