added flag for config file location

This commit is contained in:
Shreyas Goenka 2023-05-21 22:48:38 +02:00
parent a21fbdd383
commit 350053487a
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 15 additions and 5 deletions

View File

@ -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)
}

View File

@ -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)
}