From 89146ff50824c482681c35ebe5f0dc9b9f8f9498 Mon Sep 17 00:00:00 2001 From: "Han Verstraete (OpenFaaS Ltd)" Date: Wed, 19 Nov 2025 14:05:11 +0100 Subject: [PATCH] Fix template pull stack command Signed-off-by: Han Verstraete (OpenFaaS Ltd) --- commands/fetch_templates.go | 22 ++++++++++++++++++++-- commands/template_pull_stack.go | 13 ++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/commands/fetch_templates.go b/commands/fetch_templates.go index 81b01abd..ec0eff35 100644 --- a/commands/fetch_templates.go +++ b/commands/fetch_templates.go @@ -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 @@ -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) diff --git a/commands/template_pull_stack.go b/commands/template_pull_stack.go index 6b5bc1ed..5858326f 100644 --- a/commands/template_pull_stack.go +++ b/commands/template_pull_stack.go @@ -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) { @@ -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 {