mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 10:23:03 +08:00
simplified PromptForInputs
This commit is contained in:
parent
b323c3db20
commit
ea94c2de1f
@ -179,18 +179,9 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
|
|
||||||
var questions []*survey.Question
|
var questions []*survey.Question
|
||||||
|
|
||||||
if po.Name == "" {
|
processProjectName(po.Name, &questions)
|
||||||
questions = append(questions, InputQuestion("Name", "The name of the project", "My Project", true))
|
|
||||||
} else {
|
|
||||||
fmt.Println("Project Name: " + po.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if po.BinaryName == "" {
|
processBinaryName(po.BinaryName, po.Name, &questions)
|
||||||
var binaryNameComputed = computeBinaryName(po.Name)
|
|
||||||
questions = append(questions, InputQuestion("BinaryName", "The output binary name", binaryNameComputed, true))
|
|
||||||
} else {
|
|
||||||
fmt.Println("Output binary Name: " + po.BinaryName)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := processOutputDirectory(po.OutputDirectory, &questions)
|
err := processOutputDirectory(po.OutputDirectory, &questions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -242,35 +233,10 @@ func (po *ProjectOptions) PromptForInputs() error {
|
|||||||
|
|
||||||
// Populate template details
|
// Populate template details
|
||||||
templateMetadata := templateDetails[po.Template].Metadata
|
templateMetadata := templateDetails[po.Template].Metadata
|
||||||
if templateMetadata["frontenddir"] != nil {
|
|
||||||
po.FrontEnd = &frontend{}
|
|
||||||
po.FrontEnd.Dir = templateMetadata["frontenddir"].(string)
|
|
||||||
}
|
|
||||||
if templateMetadata["install"] != nil {
|
|
||||||
if po.FrontEnd == nil {
|
|
||||||
return fmt.Errorf("install set in template metadata but not frontenddir")
|
|
||||||
}
|
|
||||||
po.FrontEnd.Install = templateMetadata["install"].(string)
|
|
||||||
}
|
|
||||||
if templateMetadata["build"] != nil {
|
|
||||||
if po.FrontEnd == nil {
|
|
||||||
return fmt.Errorf("build set in template metadata but not frontenddir")
|
|
||||||
}
|
|
||||||
po.FrontEnd.Build = templateMetadata["build"].(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
if templateMetadata["bridge"] != nil {
|
err = processTemplateMetadata(templateMetadata, po)
|
||||||
if po.FrontEnd == nil {
|
if err != nil {
|
||||||
return fmt.Errorf("bridge set in template metadata but not frontenddir")
|
return err
|
||||||
}
|
|
||||||
po.FrontEnd.Bridge = templateMetadata["bridge"].(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
if templateMetadata["serve"] != nil {
|
|
||||||
if po.FrontEnd == nil {
|
|
||||||
return fmt.Errorf("serve set in template metadata but not frontenddir")
|
|
||||||
}
|
|
||||||
po.FrontEnd.Serve = templateMetadata["serve"].(string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -333,3 +299,54 @@ func processOutputDirectory(outputDirectory string, questions *[]*survey.Questio
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processProjectName(name string, questions *[]*survey.Question) {
|
||||||
|
if name == "" {
|
||||||
|
*questions = append(*questions, InputQuestion("Name", "The name of the project", "My Project", true))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Project Name: " + name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func processBinaryName(binaryName string, name string, questions *[]*survey.Question) {
|
||||||
|
if binaryName == "" {
|
||||||
|
var binaryNameComputed = computeBinaryName(name)
|
||||||
|
*questions = append(*questions, InputQuestion("BinaryName", "The output binary name", binaryNameComputed, true))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Output binary Name: " + binaryName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func processTemplateMetadata(templateMetadata map[string]interface{}, po *ProjectOptions) error {
|
||||||
|
if templateMetadata["frontenddir"] != nil {
|
||||||
|
po.FrontEnd = &frontend{}
|
||||||
|
po.FrontEnd.Dir = templateMetadata["frontenddir"].(string)
|
||||||
|
}
|
||||||
|
if templateMetadata["install"] != nil {
|
||||||
|
if po.FrontEnd == nil {
|
||||||
|
return fmt.Errorf("install set in template metadata but not frontenddir")
|
||||||
|
}
|
||||||
|
po.FrontEnd.Install = templateMetadata["install"].(string)
|
||||||
|
}
|
||||||
|
if templateMetadata["build"] != nil {
|
||||||
|
if po.FrontEnd == nil {
|
||||||
|
return fmt.Errorf("build set in template metadata but not frontenddir")
|
||||||
|
}
|
||||||
|
po.FrontEnd.Build = templateMetadata["build"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if templateMetadata["bridge"] != nil {
|
||||||
|
if po.FrontEnd == nil {
|
||||||
|
return fmt.Errorf("bridge set in template metadata but not frontenddir")
|
||||||
|
}
|
||||||
|
po.FrontEnd.Bridge = templateMetadata["bridge"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if templateMetadata["serve"] != nil {
|
||||||
|
if po.FrontEnd == nil {
|
||||||
|
return fmt.Errorf("serve set in template metadata but not frontenddir")
|
||||||
|
}
|
||||||
|
po.FrontEnd.Serve = templateMetadata["serve"].(string)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user