Skip to content

Commit db7d0e9

Browse files
author
itpey
committed
update
1 parent e59cf5d commit db7d0e9

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

app/cli.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ func Create() *cli.App {
5757
}
5858

5959
if len(templates) == 0 {
60-
return fmt.Errorf(color.RedString("Error: no templates found in", templatesDirectory))
60+
if err := downloadTemplates(defaultTemplatesRepoURL); err != nil {
61+
return err
62+
}
63+
templates, err = listTemplates()
64+
if err != nil {
65+
return err
66+
}
67+
68+
clearConsole()
6169
}
6270

6371
selectedTemplate, err := selectTemplate(templates)
@@ -112,7 +120,13 @@ func Create() *cli.App {
112120
}
113121

114122
if len(templates) == 0 {
115-
return fmt.Errorf(color.RedString("Error: no templates found in", templatesDirectory))
123+
if err := downloadTemplates(defaultTemplatesRepoURL); err != nil {
124+
return err
125+
}
126+
templates, err = listTemplates()
127+
if err != nil {
128+
return err
129+
}
116130
}
117131

118132
fmt.Println(color.YellowString("Available templates:"))

app/template.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func downloadTemplates(url string) error {
156156

157157
repoName, err := extractRepoNameFromURL(url)
158158
if err != nil {
159-
return fmt.Errorf("error extracting repository name: %v", err)
159+
return fmt.Errorf(color.RedString("Error: extracting repository name: %v"), err)
160160
}
161161

162162
repoDir := repoDirectory
@@ -204,6 +204,17 @@ func deleteTemplateByName(templateName string) error {
204204
}
205205

206206
func listTemplates() ([]string, error) {
207+
208+
if _, err := os.Stat(templatesDirectory); os.IsNotExist(err) {
209+
if err := os.MkdirAll(templatesDirectory, 0755); err != nil {
210+
return nil, fmt.Errorf(color.RedString("Error: creating templates directory: %v", err))
211+
}
212+
if err := downloadTemplates(defaultTemplatesRepoURL); err != nil {
213+
return nil, err
214+
}
215+
216+
}
217+
207218
var templates []string
208219

209220
files, err := os.ReadDir(templatesDirectory)
@@ -222,6 +233,7 @@ func listTemplates() ([]string, error) {
222233

223234
func selectTemplate(templates []string) (string, error) {
224235
clearConsole()
236+
fmt.Print(color.CyanString(appNameArt))
225237
fmt.Println(color.YellowString("Select a template:"))
226238

227239
currentIndex := 0
@@ -245,18 +257,22 @@ func selectTemplate(templates []string) (string, error) {
245257
if currentIndex > 0 {
246258
currentIndex--
247259
clearConsole()
260+
fmt.Print(color.CyanString(appNameArt))
261+
248262
fmt.Println(color.YellowString("Select a template:"))
249263
printTemplateOptions(templates, currentIndex)
250264
}
251265
case keyboard.KeyArrowDown:
252266
if currentIndex < len(templates)-1 {
253267
currentIndex++
254268
clearConsole()
269+
fmt.Print(color.CyanString(appNameArt))
255270
fmt.Println(color.YellowString("Select a template:"))
256271
printTemplateOptions(templates, currentIndex)
257272
}
258273
case keyboard.KeyEnter:
259274
clearConsole()
275+
fmt.Print(color.CyanString(appNameArt))
260276
selectedTemplate := templates[currentIndex]
261277
return selectedTemplate, nil
262278
case keyboard.KeyEsc:

app/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func getDefaultDirectory(name string) string {
4949
func runCommand(command string, args []string, projectPath string, description string) error {
5050
cmd := exec.Command(command, args...)
5151
cmd.Dir = projectPath
52-
fmt.Printf("Running %s ...\n", description)
52+
fmt.Printf("Running %s...\n", description)
5353

5454
// Execute the command
5555
output, err := cmd.CombinedOutput()

0 commit comments

Comments
 (0)