You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. // Package cmd provides subcommands to the gitea binary - such as "web" or
  5. // "admin".
  6. package cmd
  7. import (
  8. "errors"
  9. "fmt"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/setting"
  12. "code.gitea.io/gitea/modules/util"
  13. "github.com/urfave/cli"
  14. )
  15. // argsSet checks that all the required arguments are set. args is a list of
  16. // arguments that must be set in the passed Context.
  17. func argsSet(c *cli.Context, args ...string) error {
  18. for _, a := range args {
  19. if !c.IsSet(a) {
  20. return errors.New(a + " is not set")
  21. }
  22. if util.IsEmptyString(a) {
  23. return errors.New(a + " is required")
  24. }
  25. }
  26. return nil
  27. }
  28. func initDB() error {
  29. return initDBDisableConsole(false)
  30. }
  31. func initDBDisableConsole(disableConsole bool) error {
  32. setting.NewContext()
  33. setting.InitDBConfig()
  34. setting.NewXORMLogService(disableConsole)
  35. if err := models.SetEngine(); err != nil {
  36. return fmt.Errorf("models.SetEngine: %v", err)
  37. }
  38. return nil
  39. }