mirror of https://github.com/databricks/cli.git
Rename init project-dir flag to output-dir (#676)
## Changes This PR: 1. Renames the project-dir flag to output-dir 2. Makes the project dir flag optional. When unspecified we default to the current working directory. ## Tests Manually --------- Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
This commit is contained in:
parent
56dcd3f0a7
commit
042fbaa614
|
@ -42,10 +42,9 @@ func newInitCommand() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
var configFile string
|
var configFile string
|
||||||
var projectDir string
|
var outputDir string
|
||||||
cmd.Flags().StringVar(&configFile, "config-file", "", "File containing input parameters for template initialization.")
|
cmd.Flags().StringVar(&configFile, "config-file", "", "File containing input parameters for template initialization.")
|
||||||
cmd.Flags().StringVar(&projectDir, "project-dir", "", "The project will be initialized in this directory.")
|
cmd.Flags().StringVar(&outputDir, "output-dir", "", "Directory to write the initialized template to.")
|
||||||
cmd.MarkFlagRequired("project-dir")
|
|
||||||
|
|
||||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
templatePath := args[0]
|
templatePath := args[0]
|
||||||
|
@ -54,7 +53,7 @@ func newInitCommand() *cobra.Command {
|
||||||
if !isRepoUrl(templatePath) {
|
if !isRepoUrl(templatePath) {
|
||||||
// skip downloading the repo because input arg is not a URL. We assume
|
// skip downloading the repo because input arg is not a URL. We assume
|
||||||
// it's a path on the local file system in that case
|
// it's a path on the local file system in that case
|
||||||
return template.Materialize(ctx, configFile, templatePath, projectDir)
|
return template.Materialize(ctx, configFile, templatePath, outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the template in a temporary directory
|
// Download the template in a temporary directory
|
||||||
|
@ -72,7 +71,7 @@ func newInitCommand() *cobra.Command {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(templateDir)
|
defer os.RemoveAll(templateDir)
|
||||||
|
|
||||||
return template.Materialize(ctx, configFile, templateDir, projectDir)
|
return template.Materialize(ctx, configFile, templateDir, outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
@ -16,8 +16,8 @@ const schemaFileName = "databricks_template_schema.json"
|
||||||
// ctx: context containing a cmdio object. This is used to prompt the user
|
// ctx: context containing a cmdio object. This is used to prompt the user
|
||||||
// configFilePath: file path containing user defined config values
|
// configFilePath: file path containing user defined config values
|
||||||
// templateRoot: root of the template definition
|
// templateRoot: root of the template definition
|
||||||
// projectDir: root of directory where to initialize the project
|
// outputDir: root of directory where to initialize the template
|
||||||
func Materialize(ctx context.Context, configFilePath, templateRoot, projectDir string) error {
|
func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir string) error {
|
||||||
templatePath := filepath.Join(templateRoot, templateDirName)
|
templatePath := filepath.Join(templateRoot, templateDirName)
|
||||||
libraryPath := filepath.Join(templateRoot, libraryDirName)
|
libraryPath := filepath.Join(templateRoot, libraryDirName)
|
||||||
schemaPath := filepath.Join(templateRoot, schemaFileName)
|
schemaPath := filepath.Join(templateRoot, schemaFileName)
|
||||||
|
@ -48,7 +48,7 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, projectDir s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk and render the template, since input configuration is complete
|
// Walk and render the template, since input configuration is complete
|
||||||
r, err := newRenderer(ctx, config.values, templatePath, libraryPath, projectDir)
|
r, err := newRenderer(ctx, config.values, templatePath, libraryPath, outputDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue