Add --yes flag to skip prompts
This commit is contained in:
parent
1dc26e2cb7
commit
427dd93d3b
|
@ -17,13 +17,14 @@ import (
|
||||||
|
|
||||||
// install runs the first time setup of creating and
|
// install runs the first time setup of creating and
|
||||||
// migrating the database and creating the super user.
|
// 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("")
|
||||||
fmt.Println("** First time installation **")
|
fmt.Println("** First time installation **")
|
||||||
fmt.Printf("** IMPORTANT: This will wipe existing listmonk tables and types in the DB '%s' **",
|
fmt.Printf("** IMPORTANT: This will wipe existing listmonk tables and types in the DB '%s' **",
|
||||||
ko.String("db.database"))
|
ko.String("db.database"))
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
|
||||||
|
if prompt {
|
||||||
var ok string
|
var ok string
|
||||||
fmt.Print("Continue (y/n)? ")
|
fmt.Print("Continue (y/n)? ")
|
||||||
if _, err := fmt.Scanf("%s", &ok); err != nil {
|
if _, err := fmt.Scanf("%s", &ok); err != nil {
|
||||||
|
@ -33,6 +34,7 @@ func install(app *App, qMap goyesql.Queries) {
|
||||||
fmt.Println("Installation cancelled.")
|
fmt.Println("Installation cancelled.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate the tables.
|
// Migrate the tables.
|
||||||
err := installMigrate(app.DB, app)
|
err := installMigrate(app.DB, app)
|
||||||
|
|
3
main.go
3
main.go
|
@ -84,6 +84,7 @@ func init() {
|
||||||
f.Bool("install", false, "Run first time installation")
|
f.Bool("install", false, "Run first time installation")
|
||||||
f.Bool("version", false, "Current version of the build")
|
f.Bool("version", false, "Current version of the build")
|
||||||
f.Bool("new-config", false, "Generate sample config file")
|
f.Bool("new-config", false, "Generate sample config file")
|
||||||
|
f.Bool("yes", false, "Assume 'yes' to prompts, eg: during --install")
|
||||||
|
|
||||||
// Process flags.
|
// Process flags.
|
||||||
if err := f.Parse(os.Args[1:]); err != nil {
|
if err := f.Parse(os.Args[1:]); err != nil {
|
||||||
|
@ -274,7 +275,7 @@ func main() {
|
||||||
|
|
||||||
// Run the first time installation.
|
// Run the first time installation.
|
||||||
if ko.Bool("install") {
|
if ko.Bool("install") {
|
||||||
install(app, qMap)
|
install(app, qMap, !ko.Bool("yes"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue