Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template directory flag for bundle templates #675

Merged
merged 5 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/bundle/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down