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 package bundle
import ( import (
"path/filepath"
"github.com/databricks/cli/libs/template" "github.com/databricks/cli/libs/template"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -11,13 +13,19 @@ var initCmd = &cobra.Command{
Long: `Initialize template`, Long: `Initialize template`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { 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) return template.Materialize(args[0], targetDir)
}, },
} }
var targetDir string var targetDir string
var configFile string
func init() { func init() {
initCmd.Flags().StringVar(&targetDir, "target-dir", ".", "path to directory template will be initialized in") 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) AddCommand(initCmd)
} }

View File

@ -1,14 +1,16 @@
package template package template
import "path/filepath" import (
"path/filepath"
)
const ConfigFileName = "config.json" const ConfigFileName = "config.json"
const SchemaFileName = "schema.json" const schemaFileName = "schema.json"
const TemplateDirName = "template" const templateDirName = "template"
func Materialize(templatePath, instancePath string) error { func Materialize(templatePath, instancePath string) error {
// read the file containing schema for template input parameters // 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 { if err != nil {
return err return err
} }
@ -20,5 +22,5 @@ func Materialize(templatePath, instancePath string) error {
} }
// materialize the template // materialize the template
return WalkFileTree(config, filepath.Join(templatePath, TemplateDirName), instancePath) return WalkFileTree(config, filepath.Join(templatePath, templateDirName), instancePath)
} }