2021-11-20 10:34:31 +00:00
package interact
import (
2021-11-28 00:04:20 +00:00
"github.com/AlecAivazis/survey/v2"
2021-11-20 10:34:31 +00:00
"ledo/app/modules/config"
)
func InitLedoProject ( dockerConfig config . DockerMap ) ( config . DockerMap , error ) {
if dockerConfig . Registry == "" {
2021-11-28 00:04:20 +00:00
dockerConfig . Registry = ""
2021-11-20 10:34:31 +00:00
}
if dockerConfig . Shell == "" {
dockerConfig . Shell = "/bin/bash"
}
if dockerConfig . Username == "" {
dockerConfig . Username = "root"
}
var qs = [ ] * survey . Question {
{
2021-11-28 00:04:20 +00:00
Name : "Registry" ,
Prompt : & survey . Input { Message : "Enter docker registry address: " , Default : dockerConfig . Registry , Help : "Docker registry for main service image" } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
{
2021-11-28 00:04:20 +00:00
Name : "Namespace" ,
Prompt : & survey . Input { Message : "Enter project namespace: " , Default : dockerConfig . Namespace , Help : "Project namespace (eq. GitLab project group)" } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
{
2021-11-28 00:04:20 +00:00
Name : "Name" ,
Prompt : & survey . Input { Message : "Enter project name: " , Default : dockerConfig . Name } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
{
2021-11-28 00:04:20 +00:00
Name : "MainService" ,
Prompt : & survey . Input { Message : "Enter docker-compose main service name: " , Default : dockerConfig . MainService , Help : "Main service, important if you want use ledo shell command or ledo run command" } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
{
2021-11-28 00:04:20 +00:00
Name : "Shell" ,
Prompt : & survey . Input { Message : "Enter default shell: " , Default : dockerConfig . Shell } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
{
2021-11-28 00:04:20 +00:00
Name : "Username" ,
Prompt : & survey . Input { Message : "Enter docker main service username: " , Default : dockerConfig . Username , Help : "Default user, if set ledo run command was execute with sudo user" } ,
Validate : survey . Required ,
2021-11-20 10:34:31 +00:00
Transform : survey . ToLower ,
} ,
}
err := survey . Ask ( qs , & dockerConfig )
if err != nil {
return config . DockerMap { } , err
}
return dockerConfig , err
}
2021-11-28 00:04:20 +00:00
func InitAdvancedConfigurationAsk ( question string ) bool {
2021-11-20 10:34:31 +00:00
runAdv := false
2021-11-28 00:04:20 +00:00
prompt := & survey . Confirm { Message : question }
2021-11-20 10:34:31 +00:00
survey . AskOne ( prompt , & runAdv )
return runAdv
2021-11-28 00:04:20 +00:00
}