mirror of https://github.com/databricks/cli.git
added flag for config file location
This commit is contained in:
parent
a21fbdd383
commit
350053487a
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue