MCPcopy
hub / github.com/writefreely/writefreely / DoConfig

Function DoConfig

app.go:649–697  ·  view source on GitHub ↗

DoConfig runs the interactive configuration process.

(app *App, configSections string)

Source from the content-addressed store, hash-verified

647
648// DoConfig runs the interactive configuration process.
649func DoConfig(app *App, configSections string) {
650 if configSections == "" {
651 configSections = "server db app"
652 }
653 // let's check there aren't any garbage in the list
654 configSectionsArray := strings.Split(configSections, " ")
655 for _, element := range configSectionsArray {
656 if element != "server" && element != "db" && element != "app" {
657 log.Error("Invalid argument to --sections. Valid arguments are only \"server\", \"db\" and \"app\"")
658 os.Exit(1)
659 }
660 }
661 d, err := config.Configure(app.cfgFile, configSections)
662 if err != nil {
663 log.Error("Unable to configure: %v", err)
664 os.Exit(1)
665 }
666 app.cfg = d.Config
667 connectToDatabase(app)
668 defer shutdown(app)
669
670 if !app.db.DatabaseInitialized() {
671 err = adminInitDatabase(app)
672 if err != nil {
673 log.Error(err.Error())
674 os.Exit(1)
675 }
676 } else {
677 log.Info("Database already initialized.")
678 }
679
680 if d.User != nil {
681 u := &User{
682 Username: d.User.Username,
683 HashedPass: d.User.HashedPass,
684 Created: time.Now().Truncate(time.Second).UTC(),
685 }
686
687 // Create blog
688 log.Info("Creating user %s...\n", u.Username)
689 err = app.db.CreateUser(app.cfg, u, app.cfg.App.SiteName, "")
690 if err != nil {
691 log.Error("Unable to create user: %s", err)
692 os.Exit(1)
693 }
694 log.Info("Done!")
695 }
696 os.Exit(0)
697}
698
699// GenerateKeyFiles creates app encryption keys and saves them into the configured KeysParentDir.
700func GenerateKeyFiles(app *App) error {

Callers 2

interactiveConfigActionFunction · 0.92
legacyActionsFunction · 0.92

Calls 6

ConfigureFunction · 0.92
connectToDatabaseFunction · 0.85
shutdownFunction · 0.85
adminInitDatabaseFunction · 0.85
DatabaseInitializedMethod · 0.65
CreateUserMethod · 0.65

Tested by

no test coverage detected