-
Notifications
You must be signed in to change notification settings - Fork 39
/
blade.go
56 lines (46 loc) · 1.11 KB
/
blade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
log "github.com/Sirupsen/logrus"
"os"
"path"
)
type Blade struct {
Template string `yaml:"template"`
Interpolation string `yaml:"interpolation"`
Source string `yaml:"source"`
Out string `yaml:"out"`
IncludeContents bool `yaml:"contents"`
DryRun bool
Mount string `yaml:"mount"`
}
func (b *Blade) Run() {
if b.Mount != "" {
template := path.Join(b.Mount, "Contents.json")
if _, err := os.Stat(template); os.IsNotExist(err) {
log.Fatalf("A mount must point to an image catalog (Contents.json missing)")
}
b.Out = b.Mount
b.Template = template
}
c := NewContentsFromFile(b.Template)
var converter Converter
if b.DryRun {
converter = NewDryrunConverter()
} else {
cv := NewResizeConverter()
cv.Interpolation = b.Interpolation
converter = cv
}
r := NewRunner(c, converter, b.Source)
if b.Out != "" {
err := os.MkdirAll(b.Out, 0755)
if err != nil {
log.Fatalf("Cannot create output directory '%s' (%s)", b.Out, err)
}
r.OutDir = b.Out
}
if b.IncludeContents {
r.GenerateContents = true
}
r.run()
}