This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
export.go
74 lines (64 loc) · 1.48 KB
/
export.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
package cmd
import (
"flag"
"fmt"
"github.com/sclevine/cflocal/engine"
"github.com/sclevine/cflocal/local"
)
type Export struct {
UI UI
Stager Stager
Runner Runner
FS FS
Help Help
Config Config
}
type exportOptions struct {
name, reference string
}
func (e *Export) Match(args []string) bool {
return len(args) > 0 && args[0] == "export"
}
func (e *Export) Run(args []string) error {
options, err := e.options(args)
if err != nil {
e.Help.Short()
return err
}
localYML, err := e.Config.Load()
if err != nil {
return err
}
droplet, dropletSize, err := e.FS.ReadFile(fmt.Sprintf("./%s.droplet", options.name))
if err != nil {
return err
}
defer droplet.Close()
launcher, err := e.Stager.Download("/tmp/lifecycle/launcher")
if err != nil {
return err
}
defer launcher.Close()
id, err := e.Runner.Export(&local.ExportConfig{
Droplet: engine.NewStream(droplet, dropletSize),
Launcher: launcher,
Ref: options.reference,
AppConfig: getAppConfig(options.name, localYML),
})
if err != nil {
return err
}
if options.reference != "" {
e.UI.Output("Exported %s as %s with ID: %s", options.name, options.reference, id)
} else {
e.UI.Output("Exported %s with ID: %s", options.name, id)
}
return nil
}
func (*Export) options(args []string) (*exportOptions, error) {
options := &exportOptions{}
return options, parseOptions(args, func(name string, set *flag.FlagSet) {
options.name = name
set.StringVar(&options.reference, "r", "", "")
})
}