|
|
@ -20,10 +20,12 @@ func Configure() (*SetupData, error) { |
|
|
|
|
|
|
|
|
|
|
|
data.Config, err = Load() |
|
|
|
data.Config, err = Load() |
|
|
|
var action string |
|
|
|
var action string |
|
|
|
|
|
|
|
isNewCfg := false |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("No configuration yet. Creating new.") |
|
|
|
fmt.Println("No configuration yet. Creating new.") |
|
|
|
data.Config = New() |
|
|
|
data.Config = New() |
|
|
|
action = "generate" |
|
|
|
action = "generate" |
|
|
|
|
|
|
|
isNewCfg = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Println("Configuration loaded.") |
|
|
|
fmt.Println("Configuration loaded.") |
|
|
|
action = "update" |
|
|
|
action = "update" |
|
|
@ -126,62 +128,91 @@ func Configure() (*SetupData, error) { |
|
|
|
title(" Database setup ") |
|
|
|
title(" Database setup ") |
|
|
|
fmt.Println() |
|
|
|
fmt.Println() |
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
selPrompt = promptui.Select{ |
|
|
|
Templates: tmpls, |
|
|
|
Templates: selTmpls, |
|
|
|
Label: "Username", |
|
|
|
Label: "Database driver", |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Items: []string{"MySQL", "SQLite"}, |
|
|
|
Default: data.Config.Database.User, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
data.Config.Database.User, err = prompt.Run() |
|
|
|
sel, _, err := selPrompt.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return data, err |
|
|
|
return data, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
if sel == 0 { |
|
|
|
Templates: tmpls, |
|
|
|
// Configure for MySQL
|
|
|
|
Label: "Password", |
|
|
|
data.Config.UseMySQL(isNewCfg) |
|
|
|
Validate: validateNonEmpty, |
|
|
|
|
|
|
|
Default: data.Config.Database.Password, |
|
|
|
|
|
|
|
Mask: '*', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data.Config.Database.Password, err = prompt.Run() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
prompt = promptui.Prompt{ |
|
|
|
Templates: tmpls, |
|
|
|
Templates: tmpls, |
|
|
|
Label: "Database name", |
|
|
|
Label: "Username", |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Default: data.Config.Database.Database, |
|
|
|
Default: data.Config.Database.User, |
|
|
|
} |
|
|
|
} |
|
|
|
data.Config.Database.Database, err = prompt.Run() |
|
|
|
data.Config.Database.User, err = prompt.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return data, err |
|
|
|
return data, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
prompt = promptui.Prompt{ |
|
|
|
Templates: tmpls, |
|
|
|
Templates: tmpls, |
|
|
|
Label: "Host", |
|
|
|
Label: "Password", |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Default: data.Config.Database.Host, |
|
|
|
Default: data.Config.Database.Password, |
|
|
|
} |
|
|
|
Mask: '*', |
|
|
|
data.Config.Database.Host, err = prompt.Run() |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
data.Config.Database.Password, err = prompt.Run() |
|
|
|
return data, err |
|
|
|
if err != nil { |
|
|
|
} |
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
prompt = promptui.Prompt{ |
|
|
|
Templates: tmpls, |
|
|
|
Templates: tmpls, |
|
|
|
Label: "Port", |
|
|
|
Label: "Database name", |
|
|
|
Validate: validatePort, |
|
|
|
Validate: validateNonEmpty, |
|
|
|
Default: fmt.Sprintf("%d", data.Config.Database.Port), |
|
|
|
Default: data.Config.Database.Database, |
|
|
|
} |
|
|
|
} |
|
|
|
dbPort, err := prompt.Run() |
|
|
|
data.Config.Database.Database, err = prompt.Run() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return data, err |
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
|
|
|
|
Templates: tmpls, |
|
|
|
|
|
|
|
Label: "Host", |
|
|
|
|
|
|
|
Validate: validateNonEmpty, |
|
|
|
|
|
|
|
Default: data.Config.Database.Host, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data.Config.Database.Host, err = prompt.Run() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
|
|
|
|
Templates: tmpls, |
|
|
|
|
|
|
|
Label: "Port", |
|
|
|
|
|
|
|
Validate: validatePort, |
|
|
|
|
|
|
|
Default: fmt.Sprintf("%d", data.Config.Database.Port), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dbPort, err := prompt.Run() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data.Config.Database.Port, _ = strconv.Atoi(dbPort) // Ignore error, as we've already validated number
|
|
|
|
|
|
|
|
} else if sel == 1 { |
|
|
|
|
|
|
|
// Configure for SQLite
|
|
|
|
|
|
|
|
data.Config.UseSQLite(isNewCfg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prompt = promptui.Prompt{ |
|
|
|
|
|
|
|
Templates: tmpls, |
|
|
|
|
|
|
|
Label: "Filename", |
|
|
|
|
|
|
|
Validate: validateNonEmpty, |
|
|
|
|
|
|
|
Default: data.Config.Database.FileName, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data.Config.Database.FileName, err = prompt.Run() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return data, err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
data.Config.Database.Port, _ = strconv.Atoi(dbPort) // Ignore error, as we've already validated number
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println() |
|
|
|
fmt.Println() |
|
|
|
title(" App setup ") |
|
|
|
title(" App setup ") |
|
|
|