move walker to a separate library

This commit is contained in:
Shreyas Goenka 2023-05-17 11:53:13 +02:00
parent 9ef3547a3a
commit 4b7a606d72
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
4 changed files with 8 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/databricks/bricks/cmd/root"
"github.com/databricks/bricks/libs/template"
"github.com/spf13/cobra"
)
@ -26,7 +27,7 @@ var initCmd = &cobra.Command{
if err != nil {
return err
}
schema := Schema{}
schema := template.Schema{}
err = json.Unmarshal(schemaBytes, &schema)
if err != nil {
return err
@ -57,7 +58,7 @@ var initCmd = &cobra.Command{
}
// materialize the template
return walkFileTree(config, filepath.Join(args[0], TemplateDirname), ".")
return template.WalkFileTree(config, filepath.Join(args[0], TemplateDirname), ".")
},
}

View File

@ -1,4 +1,4 @@
package init
package template
import (
"os"
@ -64,7 +64,7 @@ func generateFile(config map[string]any, parentDir, nameTempate, contentTemplate
return err
}
func walkFileTree(config map[string]any, templatePath, instancePath string) error {
func WalkFileTree(config map[string]any, templatePath, instancePath string) error {
enteries, err := os.ReadDir(templatePath)
if err != nil {
return err
@ -79,7 +79,7 @@ func walkFileTree(config map[string]any, templatePath, instancePath string) erro
// recusive generate files and directories inside inside our newly generated
// directory from the template defination
err = walkFileTree(config, filepath.Join(templatePath, entry.Name()), filepath.Join(instancePath, dirName))
err = WalkFileTree(config, filepath.Join(templatePath, entry.Name()), filepath.Join(instancePath, dirName))
if err != nil {
return err
}

View File

@ -1,4 +1,4 @@
package init
package template
import (
"errors"

View File

@ -1,4 +1,4 @@
package init
package template
import (
"fmt"