Skip to content

Commit

Permalink
Add --yes flag to skip prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 30, 2019
1 parent 1dc26e2 commit 427dd93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import (

// install runs the first time setup of creating and
// migrating the database and creating the super user.
func install(app *App, qMap goyesql.Queries) {
func install(app *App, qMap goyesql.Queries, prompt bool) {
fmt.Println("")
fmt.Println("** First time installation **")
fmt.Printf("** IMPORTANT: This will wipe existing listmonk tables and types in the DB '%s' **",
ko.String("db.database"))
fmt.Println("")

var ok string
fmt.Print("Continue (y/n)? ")
if _, err := fmt.Scanf("%s", &ok); err != nil {
logger.Fatalf("Error reading value from terminal: %v", err)
}
if strings.ToLower(ok) != "y" {
fmt.Println("Installation cancelled.")
return
if prompt {
var ok string
fmt.Print("Continue (y/n)? ")
if _, err := fmt.Scanf("%s", &ok); err != nil {
logger.Fatalf("Error reading value from terminal: %v", err)
}
if strings.ToLower(ok) != "y" {
fmt.Println("Installation cancelled.")
return
}
}

// Migrate the tables.
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func init() {
f.Bool("install", false, "Run first time installation")
f.Bool("version", false, "Current version of the build")
f.Bool("new-config", false, "Generate sample config file")
f.Bool("yes", false, "Assume 'yes' to prompts, eg: during --install")

// Process flags.
if err := f.Parse(os.Args[1:]); err != nil {
Expand Down Expand Up @@ -274,7 +275,7 @@ func main() {

// Run the first time installation.
if ko.Bool("install") {
install(app, qMap)
install(app, qMap, !ko.Bool("yes"))
return
}

Expand Down

0 comments on commit 427dd93

Please sign in to comment.