Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 20 additions & 2 deletions commands/fetch_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func canWriteLanguage(existingLanguages []string, language string, overwriteTemp
// It returns the existing languages and the fetched languages
// It also returns an error if the templates cannot be read
func moveTemplates(localTemplatesDir, extractedPath, templateName string, overwriteTemplate bool, repository string, refName string, sha string) ([]string, []string, error) {
// Get the template name without prefix
template := strings.SplitN(templateName, "@", 2)[0]

var (
existingLanguages []string
Expand Down Expand Up @@ -197,13 +199,29 @@ func moveTemplates(localTemplatesDir, extractedPath, templateName string, overwr
refSuffix = "@" + refName
}

// Only copy the requested template when a template name is provided
// copy all templates otherwise.
if len(template) > 0 && language != template {
continue
}

if canWriteLanguage(existingLanguages, language, overwriteTemplate) {
// Do cp here
languageSrc := filepath.Join(extractedPath, TemplateDirectory, language)
languageDest := filepath.Join(localTemplatesDir, language)

var languageDest string

if len(templateName) > 0 {
languageDest = filepath.Join(localTemplatesDir, templateName)
} else {
languageDest = filepath.Join(localTemplatesDir, language)
if refName != "" {
languageDest += "@" + refName
}
}

langName := language
if refName != "" {
languageDest += "@" + refName
langName = language + "@" + refName
}
fetchedLanguages = append(fetchedLanguages, langName)
Expand Down
13 changes: 12 additions & 1 deletion commands/template_pull_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func runTemplatePullStack(cmd *cobra.Command, args []string) error {
return err
}

return pullStackTemplates([]string{}, templatesConfig, cmd)
return pullConfigTemplates(templatesConfig)
}

func loadTemplateConfig() ([]stack.TemplateSource, error) {
Expand Down Expand Up @@ -69,6 +69,17 @@ func readStackConfig() (stack.Configuration, error) {
return configField, nil
}

func pullConfigTemplates(templateSources []stack.TemplateSource) error {
for _, config := range templateSources {
fmt.Printf("Pulling template: %s from %s\n", config.Name, config.Source)

if err := pullTemplate(config.Source, config.Name, overwrite); err != nil {
return err
}
}
return nil
}

func pullStackTemplates(missingTemplates []string, templateSources []stack.TemplateSource, cmd *cobra.Command) error {

for _, val := range missingTemplates {
Expand Down
Loading