config.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package config
  2. import (
  3. "flag"
  4. "path"
  5. )
  6. const Version = "0.1.1"
  7. // Config struct to hold all the configuration settings for our application.
  8. type Config struct {
  9. BookStackEndpoint string // Ex: https://wiki.example.com
  10. BookStackAPITokenID string // token ID
  11. BookStackAPITokenSecret string // token secret
  12. GenerateHTML bool // generate static site HTML
  13. MdBookLocation string // path to the mdBook binary
  14. Concurrency int // number of concurrent goroutines
  15. DownloadLocation string // path of downloaded markdown
  16. VerboseLogs bool // print detailed logs
  17. DownloadImages bool // download static images from the wiki as well
  18. }
  19. func LoadConfig(app *Application) Config {
  20. var settings Config
  21. // Command line flags and their default values
  22. // Required
  23. flag.StringVar(&settings.BookStackEndpoint, "bookstack-url", "", "BookStack Endpoint")
  24. flag.StringVar(&settings.BookStackAPITokenID, "token-id", "", "BookStack API Token ID")
  25. flag.StringVar(&settings.BookStackAPITokenSecret, "token-secret", "", "BookStack API Token Secret")
  26. // Optional
  27. flag.IntVar(&settings.Concurrency, "concurrency", 10, "Number of concurrent page downloads")
  28. // flag.BoolVar(&settings.GenerateHTML, "generate-html", true, "Generate Static Site HTML or just markdown")
  29. // flag.StringVar(&settings.MdBookLocation, "mdbook-location", "mdbook", "Custom path of mdbook binary")
  30. flag.StringVar(&settings.DownloadLocation, "download-location", "./book", "Path of downloaded markdown")
  31. flag.BoolVar(&settings.VerboseLogs, "verbose", false, "Print detailed logs")
  32. // flag.BoolVar(&settings.DownloadImages, "download-images", true, "Download static images from the wiki")
  33. flag.Parse()
  34. // Clean up file paths.
  35. settings.MdBookLocation = path.Clean(settings.MdBookLocation)
  36. settings.DownloadLocation = path.Clean(settings.DownloadLocation)
  37. return settings
  38. }