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. store := storage.NewStorage(
  26. cfg.DatabaseURL(),
  27. cfg.DatabaseMaxConnections(),
  28. )
  29. if *flagInfo {
  30. info()
  31. return
  32. }
  33. if *flagVersion {
  34. fmt.Println(version.Version)
  35. return
  36. }
  37. if *flagMigrate {
  38. store.Migrate()
  39. return
  40. }
  41. if *flagFlushSessions {
  42. flushSessions(store)
  43. return
  44. }
  45. if *flagCreateAdmin {
  46. createAdmin(store)
  47. return
  48. }
  49. if *flagResetPassword {
  50. resetPassword(store)
  51. return
  52. }
  53. if *flagDebugMode {
  54. logger.EnableDebug()
  55. }
  56. // start daemon
  57. daemon.Run(cfg, store)
  58. }