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 3 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
13 changes: 7 additions & 6 deletions cmd/bundle/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ func newInitCommand() *cobra.Command {

var configFile string
var projectDir string
var templateDir string
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(&templateDir, "template-directory", "", "Directory within repository that holds the template specification.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be consistent with the other args; we use -dir suffix elsewhere, so should do the same here.

cmd.MarkFlagRequired("project-dir")

cmd.RunE = func(cmd *cobra.Command, args []string) error {
Expand All @@ -60,19 +62,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, projectDir)
defer os.RemoveAll(repoDir)
return template.Materialize(ctx, configFile, filepath.Join(repoDir, templateDir), projectDir)
}

return cmd
Expand Down