cli.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/storage"
  11. "github.com/miniflux/miniflux/version"
  12. )
  13. // Parse parses command line arguments.
  14. func Parse() {
  15. flagInfo := flag.Bool("info", false, "Show application information")
  16. flagVersion := flag.Bool("version", false, "Show application version")
  17. flagMigrate := flag.Bool("migrate", false, "Migrate database schema")
  18. flagFlushSessions := flag.Bool("flush-sessions", false, "Flush all sessions (disconnect users)")
  19. flagCreateAdmin := flag.Bool("create-admin", false, "Create admin user")
  20. flagResetPassword := flag.Bool("reset-password", false, "Reset user password")
  21. flag.Parse()
  22. cfg := config.NewConfig()
  23. store := storage.NewStorage(
  24. cfg.DatabaseURL(),
  25. cfg.DatabaseMaxConnections(),
  26. )
  27. if *flagInfo {
  28. info()
  29. return
  30. }
  31. if *flagVersion {
  32. fmt.Println(version.Version)
  33. return
  34. }
  35. if *flagMigrate {
  36. store.Migrate()
  37. return
  38. }
  39. if *flagFlushSessions {
  40. flushSessions(store)
  41. return
  42. }
  43. if *flagCreateAdmin {
  44. createAdmin(store)
  45. return
  46. }
  47. if *flagResetPassword {
  48. resetPassword(store)
  49. return
  50. }
  51. daemon.Run(cfg, store)
  52. }