Skip to content

Commit 4c286a8

Browse files
author
den-rgb
committed
OCM-13094 | feat: Adding extra info message for user to specify template-dir when calling custom template
1 parent 32f9a5c commit 4c286a8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cmd/create/network/cmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func extractTemplateCommand(r *rosa.Runtime, argv []string, options *opts.Networ
186186
if *templateCommand == defaultTemplate {
187187
*templateFile = CloudFormationTemplateFile
188188
} else {
189+
if options.TemplateDir == opts.DefaultTemplateDir {
190+
return fmt.Errorf("when using a custom template please use `--template-dir` to specify the template directory")
191+
}
189192
templateDir := options.TemplateDir
190193
*templateFile = helper.SelectTemplate(templateDir, *templateCommand)
191194
templateBody, err := os.ReadFile(*templateFile)

cmd/create/network/cmd_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,27 @@ var _ = Describe("Validation functions", func() {
111111
templateCommand := ""
112112
templateFile := ""
113113
options := &opts.NetworkUserOptions{}
114-
options.TemplateDir = "cmd/create/network/templates"
114+
options.TemplateDir = "cmd/create/other/templates"
115115

116116
extractTemplateCommand(r, argv, options, &templateCommand, &templateFile)
117117

118118
Expect(templateCommand).To(Equal("my-template"))
119-
Expect(templateFile).To(Equal("cmd/create/network/templates/my-template/cloudformation.yaml"))
119+
Expect(templateFile).To(Equal("cmd/create/other/templates/my-template/cloudformation.yaml"))
120+
})
121+
122+
It("should extract the error telling the user to use `--template-dir", func() {
123+
argv := []string{"my-template", "--param", "key=value"}
124+
r := rosa.NewRuntime()
125+
templateCommand := ""
126+
templateFile := ""
127+
options := &opts.NetworkUserOptions{}
128+
options.TemplateDir = "cmd/create/network/templates"
129+
130+
err := extractTemplateCommand(r, argv, options, &templateCommand, &templateFile)
131+
132+
Expect(err).To(HaveOccurred())
133+
Expect(err).To(MatchError("when using a custom template please use `--template-dir`" +
134+
" to specify the template directory"))
120135
})
121136

122137
It("should use the default template when the extracted template command is 'rosa-quickstart-default-vpc'", func() {

0 commit comments

Comments
 (0)