Skip to content

Commit 6e28e11

Browse files
weltekialexellis
authored andcommitted
Fix template pull stack command
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent 0dc05df commit 6e28e11

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

commands/fetch_templates.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ func canWriteLanguage(existingLanguages []string, language string, overwriteTemp
155155
// It returns the existing languages and the fetched languages
156156
// It also returns an error if the templates cannot be read
157157
func moveTemplates(localTemplatesDir, extractedPath, templateName string, overwriteTemplate bool, repository string, refName string, sha string) ([]string, []string, error) {
158+
// Get the template name without prefix
159+
template := strings.SplitN(templateName, "@", 2)[0]
158160

159161
var (
160162
existingLanguages []string
@@ -197,13 +199,29 @@ func moveTemplates(localTemplatesDir, extractedPath, templateName string, overwr
197199
refSuffix = "@" + refName
198200
}
199201

202+
// Only copy the requested template when a template name is provided
203+
// copy all templates otherwise.
204+
if len(template) > 0 && language != template {
205+
continue
206+
}
207+
200208
if canWriteLanguage(existingLanguages, language, overwriteTemplate) {
201209
// Do cp here
202210
languageSrc := filepath.Join(extractedPath, TemplateDirectory, language)
203-
languageDest := filepath.Join(localTemplatesDir, language)
211+
212+
var languageDest string
213+
214+
if len(templateName) > 0 {
215+
languageDest = filepath.Join(localTemplatesDir, templateName)
216+
} else {
217+
languageDest = filepath.Join(localTemplatesDir, language)
218+
if refName != "" {
219+
languageDest += "@" + refName
220+
}
221+
}
222+
204223
langName := language
205224
if refName != "" {
206-
languageDest += "@" + refName
207225
langName = language + "@" + refName
208226
}
209227
fetchedLanguages = append(fetchedLanguages, langName)

commands/template_pull_stack.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func runTemplatePullStack(cmd *cobra.Command, args []string) error {
4141
return err
4242
}
4343

44-
return pullStackTemplates([]string{}, templatesConfig, cmd)
44+
return pullConfigTemplates(templatesConfig)
4545
}
4646

4747
func loadTemplateConfig() ([]stack.TemplateSource, error) {
@@ -69,6 +69,17 @@ func readStackConfig() (stack.Configuration, error) {
6969
return configField, nil
7070
}
7171

72+
func pullConfigTemplates(templateSources []stack.TemplateSource) error {
73+
for _, config := range templateSources {
74+
fmt.Printf("Pulling template: %s from %s\n", config.Name, config.Source)
75+
76+
if err := pullTemplate(config.Source, config.Name, overwrite); err != nil {
77+
return err
78+
}
79+
}
80+
return nil
81+
}
82+
7283
func pullStackTemplates(missingTemplates []string, templateSources []stack.TemplateSource, cmd *cobra.Command) error {
7384

7485
for _, val := range missingTemplates {

0 commit comments

Comments
 (0)