forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalize_release.go
60 lines (48 loc) · 1.21 KB
/
finalize_release.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
package cmd
import (
semver "github.com/cppforlife/go-semi-semantic/version"
boshrel "github.com/cloudfoundry/bosh-cli/release"
boshreldir "github.com/cloudfoundry/bosh-cli/releasedir"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type FinalizeReleaseCmd struct {
releaseReader boshrel.Reader
releaseDir boshreldir.ReleaseDir
ui boshui.UI
}
func NewFinalizeReleaseCmd(
releaseReader boshrel.Reader,
releaseDir boshreldir.ReleaseDir,
ui boshui.UI,
) FinalizeReleaseCmd {
return FinalizeReleaseCmd{
releaseReader: releaseReader,
releaseDir: releaseDir,
ui: ui,
}
}
func (c FinalizeReleaseCmd) Run(opts FinalizeReleaseOpts) error {
release, err := c.releaseReader.Read(opts.Args.Path)
if err != nil {
return err
}
if len(opts.Name) > 0 {
release.SetName(opts.Name)
}
version := semver.Version(opts.Version)
if !version.Empty() {
release.SetVersion(version.AsString())
} else {
version, err := c.releaseDir.NextFinalVersion(release.Name())
if err != nil {
return err
}
release.SetVersion(version.AsString())
}
err = c.releaseDir.FinalizeRelease(release, opts.Force)
if err != nil {
return err
}
ReleaseTables{Release: release}.Print(c.ui)
return nil
}