@@ -20,6 +20,8 @@ type TemplateType string
20
20
const (
21
21
// Snippet will mark a template as a part of a file.
22
22
Snippet TemplateType = "snippet"
23
+ // FullSnippet will mark a template that includes header and footer as a part of a file.
24
+ FullSnippet TemplateType = "fullSnippet"
23
25
// File will mark a templates as a full file.
24
26
File TemplateType = "file"
25
27
// Directory will mark a template as a directory.
@@ -99,7 +101,7 @@ func (t *SSHTemplates) Validate() (err error) {
99
101
return
100
102
}
101
103
102
- // Template represents on template file.
104
+ // Template represents a template file.
103
105
type Template struct {
104
106
* template.Template
105
107
Name string `json:"name"`
@@ -118,8 +120,8 @@ func (t *Template) Validate() error {
118
120
return nil
119
121
case t .Name == "" :
120
122
return errors .New ("template name cannot be empty" )
121
- case t .Type != Snippet && t .Type != File && t .Type != Directory :
122
- return errors .Errorf ("invalid template type %s, it must be %s, %s, or %s" , t .Type , Snippet , File , Directory )
123
+ case t .Type != Snippet && t .Type != File && t .Type != Directory && t . Type != FullSnippet :
124
+ return errors .Errorf ("invalid template type %s, it must be %s, %s, %s, or %s" , t .Type , Snippet , FullSnippet , File , Directory )
123
125
case t .TemplatePath == "" && t .Type != Directory && len (t .Content ) == 0 :
124
126
return errors .New ("template template cannot be empty" )
125
127
case t .TemplatePath != "" && t .Type == Directory :
@@ -257,11 +259,17 @@ func (o *Output) Write() error {
257
259
return err
258
260
}
259
261
260
- if o .Type == File {
262
+ switch o .Type {
263
+ case File :
261
264
return fileutil .WriteFile (path , o .Content , 0600 )
265
+ case Snippet :
266
+ return fileutil .WriteSnippet (path , o .Content , 0600 )
267
+ case FullSnippet :
268
+ lines := strings .Split (string (o .Content ), "\n " )
269
+ return fileutil .WriteFullSnippet (path , o .Content , lines [0 ], lines [len (lines )- 1 ], 0600 )
270
+ default :
271
+ return errors .Errorf ("unexpected output template type %s" , string (o .Type ))
262
272
}
263
-
264
- return fileutil .WriteSnippet (path , o .Content , 0600 )
265
273
}
266
274
267
275
func mkdir (path string , perm os.FileMode ) error {
0 commit comments