Skip to content

Commit

Permalink
added prompt for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
joicemjoseph committed Sep 30, 2020
1 parent b895e5d commit 4775d1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 27 additions & 1 deletion install.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package main

func (app *App) installSchema() int {
import (
"fmt"
"strings"
)

func (app *App) installSchema(prompt bool) int {
if prompt {
fmt.Println("")
fmt.Println("** first time installation **")
fmt.Printf("** IMPORTANT: This will wipe existing dictmaker tables and types in the DB '%s' **",
ko.String("db.db"))
fmt.Println("")

var ok string

fmt.Print("continue (y/n)? ")

if _, err := fmt.Scanf("%s", &ok); err != nil {
app.logger.Fatalf("error reading value from terminal: %v", err)
}

if strings.ToLower(ok) != "y" {
fmt.Println("install cancelled.")
return 1
}
}

q, err := app.fs.Read("/schema.sql")
if err != nil {
app.logger.Fatal(err.Error())
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func init() {
"path to one or more config files (will be merged in order)")
f.String("site", "", "path to a site theme. If left empty, only the APIs will run.")
f.Bool("install", false, "run first time installation")
f.Bool("prompt", true, "prompt before each steps in installation")
f.Bool("version", false, "current version of the build")
f.Parse(os.Args[1:])

Expand Down Expand Up @@ -127,7 +128,7 @@ func main() {

// Install schema.
if ko.Bool("install") {
os.Exit(app.installSchema())
os.Exit(app.installSchema(ko.Bool("prompt")))
}

// Load SQL queries.
Expand Down

0 comments on commit 4775d1e

Please sign in to comment.