-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
68 lines (55 loc) · 1.83 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"os"
"github.com/pivotal-cf/jhanda"
"github.com/pivotal-cf/winfs-injector/tile"
"github.com/pivotal-cf/winfs-injector/winfsinjector"
)
const usageText = `winfs-injector injects the Windows 2016 root file system into the Windows 2016 Runtime Tile.
Usage: winfs-injector
--input-tile, -i path to input tile (example: /path/to/input.pivotal)
--output-tile, -o path to output tile (example: /path/to/output.pivotal)
--preserve-extracted, -p preserve the files created during the tile extraction process (useful for debugging)
--registry, -r path to docker registry (example: /path/to/registry, default: "https://registry.hub.docker.com")
--help, -h prints this usage information
`
func main() {
var arguments struct {
InputTile string `short:"i" long:"input-tile"`
OutputTile string `short:"o" long:"output-tile"`
PreserveExtracted bool `short:"p" long:"preserve-extracted"`
Registry string `short:"r" long:"registry" default:"https://registry.hub.docker.com"`
Help bool `short:"h" long:"help"`
}
_, err := jhanda.Parse(&arguments, os.Args[1:])
if err != nil {
log.Fatal(err)
}
if arguments.Help {
printUsage()
return
}
var tileInjector = tile.NewTileInjector()
var zipper = tile.NewZipper()
var releaseCreator = winfsinjector.ReleaseCreator{}
wd, err := os.MkdirTemp("", "")
if err != nil {
log.Fatal(err)
}
if arguments.PreserveExtracted {
fmt.Fprintf(os.Stdout, "tile extraction directory: %s\n", wd)
} else {
defer os.RemoveAll(wd)
}
app := winfsinjector.NewApplication(releaseCreator, tileInjector, zipper)
err = app.Run(arguments.InputTile, arguments.OutputTile, arguments.Registry, wd)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
}
func printUsage() {
fmt.Fprint(os.Stdout, usageText)
}