Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
(GH-167) Move GetDefaultTemplatePath func to utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
sanfrancrisko committed Aug 20, 2021
1 parent bbd813f commit b7a4c05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 1 addition & 14 deletions cmd/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package new

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/puppetlabs/pdkgo/internal/pkg/pct"
Expand Down Expand Up @@ -77,7 +75,7 @@ func CreateCommand() *cobra.Command {
}

func preExecute(cmd *cobra.Command, args []string) error {
defaultTemplatePath, err := getDefaultTemplatePath()
defaultTemplatePath, err := utils.GetDefaultTemplatePath()
if err != nil {
return err
}
Expand Down Expand Up @@ -201,14 +199,3 @@ func execute(cmd *cobra.Command, args []string) error {

return nil
}

func getDefaultTemplatePath() (string, error) {
execDir, err := os.Executable()
if err != nil {
return "", err
}

defaultTemplatePath := filepath.Join(filepath.Dir(execDir), "templates")
log.Trace().Msgf("Default template path: %v", defaultTemplatePath)
return defaultTemplatePath, nil
}
11 changes: 11 additions & 0 deletions internal/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ func ChunkedCopy(dst io.Writer, src io.Reader) error {
}
}
}

func GetDefaultTemplatePath() (string, error) {
execDir, err := os.Executable()
if err != nil {
return "", err
}

defaultTemplatePath := filepath.Join(filepath.Dir(execDir), "templates")
log.Trace().Msgf("Default template path: %v", defaultTemplatePath)
return defaultTemplatePath, nil
}

0 comments on commit b7a4c05

Please sign in to comment.