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.

cmd.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "strings"
  11. "code.gitea.io/gitea/models"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/util"
  14. "github.com/urfave/cli"
  15. )
  16. // argsSet checks that all the required arguments are set. args is a list of
  17. // arguments that must be set in the passed Context.
  18. func argsSet(c *cli.Context, args ...string) error {
  19. for _, a := range args {
  20. if !c.IsSet(a) {
  21. return errors.New(a + " is not set")
  22. }
  23. if util.IsEmptyString(a) {
  24. return errors.New(a + " is required")
  25. }
  26. }
  27. return nil
  28. }
  29. // confirm waits for user input which confirms an action
  30. func confirm() (bool, error) {
  31. var response string
  32. _, err := fmt.Scanln(&response)
  33. if err != nil {
  34. return false, err
  35. }
  36. switch strings.ToLower(response) {
  37. case "y", "yes":
  38. return true, nil
  39. case "n", "no":
  40. return false, nil
  41. default:
  42. return false, errors.New(response + " isn't a correct confirmation string")
  43. }
  44. }
  45. func initDB() error {
  46. return initDBDisableConsole(false)
  47. }
  48. func initDBDisableConsole(disableConsole bool) error {
  49. setting.NewContext()
  50. setting.InitDBConfig()
  51. setting.NewXORMLogService(disableConsole)
  52. if err := models.SetEngine(); err != nil {
  53. return fmt.Errorf("models.SetEngine: %v", err)
  54. }
  55. return nil
  56. }