-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
77 lines (62 loc) · 2.56 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
69
70
71
72
73
74
75
76
77
package main
import (
"context"
"flag"
"fmt"
"os"
"path"
"strings"
"github.com/google/subcommands"
"github.com/cloudfoundry/stembuild/assets"
"github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/construct"
"github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
"github.com/cloudfoundry/stembuild/version"
)
func main() {
envs := os.Environ()
for _, env := range envs {
envName := strings.Split(env, "=")[0]
if strings.HasPrefix(envName, "GOVC_") || strings.HasPrefix(envName, "GOVMOMI_") {
_, _ = fmt.Fprintf(os.Stderr, "Warning: The following environment variable is set and might override flags provided to stembuild: %s\n", envName)
}
}
s := "./StemcellAutomation.zip"
err := os.WriteFile(s, assets.StemcellAutomation, 0644)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "Unable to write StemcellAutomation.zip")
os.Exit(1)
}
var gf commandparser.GlobalFlags
packageCmd := commandparser.NewPackageCommand(version.NewVersionGetter(), &packager.Factory{}, &commandparser.PackageMessenger{Output: os.Stderr})
packageCmd.GlobalFlags = &gf
constructCmd := commandparser.NewConstructCmd(context.Background(), &construct.Factory{}, &vcenter_manager.ManagerFactory{}, &commandparser.ConstructValidator{}, &commandparser.ConstructCmdMessenger{OutputChannel: os.Stderr})
constructCmd.GlobalFlags = &gf
var commands = make([]subcommands.Command, 0)
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
fs.BoolVar(&gf.Debug, "debug", false, "Print lots of debugging information")
fs.BoolVar(&gf.Color, "color", false, "Colorize debug output")
fs.BoolVar(&gf.ShowVersion, "version", false, "Show Stembuild version")
fs.BoolVar(&gf.ShowVersion, "v", false, "Stembuild version (shorthand)")
commander := subcommands.NewCommander(fs, path.Base(os.Args[0]))
sh := commandparser.NewStembuildHelp(commander, fs, &commands)
commander.Register(sh, "")
commands = append(commands, sh)
commander.Register(packageCmd, "")
commander.Register(constructCmd, "")
commands = append(commands, packageCmd)
commands = append(commands, constructCmd)
// Override the default usage text of Google's Subcommand with our own
fs.Usage = func() { sh.Explain(commander.Error) }
_ = fs.Parse(os.Args[1:])
if gf.ShowVersion {
_, _ = fmt.Fprintf(os.Stdout, "%s version %s, Windows Stemcell Building Tool\n\n", path.Base(os.Args[0]), version.Version)
_ = os.Remove(s)
os.Exit(0)
}
ctx := context.Background()
i := int(commander.Execute(ctx))
_ = os.Remove(s)
os.Exit(i)
}