diff --git a/pkg/commands/preview.go b/pkg/commands/preview.go index 2224f17..ec5d499 100644 --- a/pkg/commands/preview.go +++ b/pkg/commands/preview.go @@ -29,10 +29,7 @@ func (cmd *Command) previewFile(filename string) error { return fmt.Errorf("template for %s does not exist", filename) } - data, err := templateVariables(filename, tpl) - if err != nil { - return err - } + data := templateVariables(filename, tpl) if err := cmd.Renderer.RenderTemplate(cmd.Output, tpl, data); err != nil { return err diff --git a/pkg/commands/preview_test.go b/pkg/commands/preview_test.go index b307dce..ff2c777 100644 --- a/pkg/commands/preview_test.go +++ b/pkg/commands/preview_test.go @@ -35,7 +35,7 @@ func TestPreview(t *testing.T) { cmd := newTestCommand(t, false, false) err := cmd.Preview(s.files) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, s.expectedOutput, cmd.Output.(*bytes.Buffer).String()) }) } diff --git a/pkg/commands/touch.go b/pkg/commands/touch.go index 75af3da..5bcf845 100644 --- a/pkg/commands/touch.go +++ b/pkg/commands/touch.go @@ -89,10 +89,7 @@ func (cmd *Command) renderTemplate(filename string, tpl *repositories.TemplateFi } defer output.Close() - data, err := templateVariables(filename, tpl) - if err != nil { - return err - } + data := templateVariables(filename, tpl) if err := cmd.Renderer.RenderTemplate(output, tpl, data); err != nil { return err @@ -106,10 +103,10 @@ func (cmd *Command) renderTemplate(filename string, tpl *repositories.TemplateFi return nil } -func templateVariables(filename string, tpl *repositories.TemplateFile) (map[string]any, error) { +func templateVariables(filename string, tpl *repositories.TemplateFile) map[string]any { filepath, err := filepath.Abs(filename) if err != nil { - return nil, err + filepath = filename } return map[string]any{ @@ -117,5 +114,5 @@ func templateVariables(filename string, tpl *repositories.TemplateFile) (map[str "Filepath": filepath, "TemplateFilename": tpl.Path, "TemplateFilepath": tpl.Path, - }, nil + } }