5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 03:11:11 +08:00
wails/v3/internal/commands/init.go
Lea Anthony 39af86e59d
Improve project creation.
Add `template.json` to templates.
Update dependencies.
2023-08-09 21:30:06 +10:00

44 lines
967 B
Go

package commands
import (
"fmt"
"github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/templates"
"github.com/pterm/pterm"
)
func Init(options *flags.Init) error {
if options.List {
return printTemplates()
}
if options.Quiet {
pterm.DisableOutput()
}
if options.ProjectName == "" {
return fmt.Errorf("please use the -n flag to specify a project name")
}
if templates.ValidTemplateName(options.TemplateName) {
return templates.Install(options)
}
return templates.Install(options)
}
func printTemplates() error {
defaultTemplates := templates.GetDefaultTemplates()
pterm.DefaultSection.Println("Available templates")
table := pterm.TableData{{"Name", "Description"}}
for _, template := range defaultTemplates {
table = append(table, []string{template.Name, template.Description})
}
err := pterm.DefaultTable.WithHasHeader(true).WithBoxed(true).WithData(table).Render()
pterm.Println()
return err
}