diff --git a/cmd/bundle/init.go b/cmd/bundle/init.go index 973c709e4..2cc2ffbed 100644 --- a/cmd/bundle/init.go +++ b/cmd/bundle/init.go @@ -1,6 +1,8 @@ package bundle import ( + "path/filepath" + "github.com/databricks/cli/libs/template" "github.com/spf13/cobra" ) @@ -11,13 +13,19 @@ var initCmd = &cobra.Command{ Long: `Initialize template`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { + // initialize default value for config file path + if configFile == "" { + configFile = filepath.Join(targetDir, template.ConfigFileName) + } return template.Materialize(args[0], targetDir) }, } var targetDir string +var configFile string func init() { initCmd.Flags().StringVar(&targetDir, "target-dir", ".", "path to directory template will be initialized in") + initCmd.Flags().StringVar(&configFile, "config-file", "", "path to config to use for template initialization") AddCommand(initCmd) } diff --git a/libs/template/materialize.go b/libs/template/materialize.go index 8501616c0..57963d126 100644 --- a/libs/template/materialize.go +++ b/libs/template/materialize.go @@ -1,14 +1,16 @@ package template -import "path/filepath" +import ( + "path/filepath" +) const ConfigFileName = "config.json" -const SchemaFileName = "schema.json" -const TemplateDirName = "template" +const schemaFileName = "schema.json" +const templateDirName = "template" func Materialize(templatePath, instancePath string) error { // read the file containing schema for template input parameters - schema, err := ReadSchema(filepath.Join(templatePath, SchemaFileName)) + schema, err := ReadSchema(filepath.Join(templatePath, schemaFileName)) if err != nil { return err } @@ -20,5 +22,5 @@ func Materialize(templatePath, instancePath string) error { } // materialize the template - return WalkFileTree(config, filepath.Join(templatePath, TemplateDirName), instancePath) + return WalkFileTree(config, filepath.Join(templatePath, templateDirName), instancePath) }