Skip to content

Commit

Permalink
fix '-r' flags with no template files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga committed Apr 24, 2021
1 parent 6dfb0b9 commit d3504f9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ func (app *App) touchFile(file string) error {
}

source := app.resolveTemplatePath(file)
templateExists := true
if stat, err := os.Stat(source); os.IsNotExist(err) {
if err := createFile(file); err != nil {
return err
}
app.logger.Printf("create empty file %s\n", file)
return nil
templateExists = false
} else if err != nil {
return err
} else if stat.IsDir() {
Expand All @@ -119,12 +116,21 @@ func (app *App) touchFile(file string) error {
}
}

if err := renderTemplate(source, file); err != nil {
return err
}
if templateExists {
if err := renderTemplate(source, file); err != nil {
return err
}

app.logger.Printf("create from template: %s -> %s\n", source, file)
return nil
app.logger.Printf("create from template: %s -> %s\n", source, file)
return nil
} else {
if err := createFile(file); err != nil {
return err
}

app.logger.Printf("create empty file %s\n", file)
return nil
}
}

func (app *App) resolveTemplatePath(file string) string {
Expand Down

0 comments on commit d3504f9

Please sign in to comment.