cli.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. flag.Parse()
  21. cfg := config.NewConfig()
  22. store := storage.NewStorage(
  23. cfg.Get("DATABASE_URL", config.DefaultDatabaseURL),
  24. cfg.GetInt("DATABASE_MAX_CONNS", config.DefaultDatabaseMaxConns),
  25. )
  26. if *flagInfo {
  27. info()
  28. return
  29. }
  30. if *flagVersion {
  31. fmt.Println(version.Version)
  32. return
  33. }
  34. if *flagMigrate {
  35. store.Migrate()
  36. return
  37. }
  38. if *flagFlushSessions {
  39. flushSessions(store)
  40. return
  41. }
  42. if *flagCreateAdmin {
  43. createAdmin(store)
  44. return
  45. }
  46. daemon.Run(cfg, store)
  47. }