Add template directory flag for bundle templates (#675)

## Changes
This flag allows users to initialize a template from a subdirectory in
the repo root. Also enables multi template repositories.

## Tests
Manually
This commit is contained in:
shreyas-goenka 2023-08-18 11:29:48 +02:00 committed by GitHub
parent e3e9bc6def
commit ffc78b4b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -43,7 +43,9 @@ func newInitCommand() *cobra.Command {
var configFile string
var outputDir string
var templateDir string
cmd.Flags().StringVar(&configFile, "config-file", "", "File containing input parameters for template initialization.")
cmd.Flags().StringVar(&templateDir, "template-dir", "", "Directory within repository that holds the template specification.")
cmd.Flags().StringVar(&outputDir, "output-dir", "", "Directory to write the initialized template to.")
cmd.RunE = func(cmd *cobra.Command, args []string) error {
@ -59,19 +61,18 @@ func newInitCommand() *cobra.Command {
// Download the template in a temporary directory
tmpDir := os.TempDir()
templateURL := templatePath
templateDir := filepath.Join(tmpDir, repoName(templateURL))
err := os.MkdirAll(templateDir, 0755)
repoDir := filepath.Join(tmpDir, repoName(templateURL))
err := os.MkdirAll(repoDir, 0755)
if err != nil {
return err
}
// TODO: Add automated test that the downloaded git repo is cleaned up.
err = git.Clone(ctx, templateURL, "", templateDir)
err = git.Clone(ctx, templateURL, "", repoDir)
if err != nil {
return err
}
defer os.RemoveAll(templateDir)
return template.Materialize(ctx, configFile, templateDir, outputDir)
return template.Materialize(ctx, configFile, filepath.Join(repoDir, templateDir), outputDir)
}
return cmd