forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
55 lines (43 loc) · 1.16 KB
/
sync.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
package commands
import (
"fmt"
"runtime"
"strconv"
pb "gopkg.in/cheggaaa/pb.v1"
"github.com/concourse/fly/version"
update "github.com/inconshreveable/go-update"
"github.com/concourse/fly/commands/internal/displayhelpers"
"github.com/concourse/fly/rc"
)
type SyncCommand struct{}
func (command *SyncCommand) Execute(args []string) error {
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
info, err := target.Client().GetInfo()
if err != nil {
return err
}
if info.Version == version.Version {
fmt.Printf("version already matches; skipping\n")
return nil
}
client := target.Client()
body, headers, err := client.GetCLIReader(runtime.GOARCH, runtime.GOOS)
if err != nil {
return err
}
fmt.Printf("downloading fly from %s... \n", client.URL())
filesSize, _ := strconv.ParseInt(headers.Get("Content-Length"), 10, 64)
progressBar := pb.New64(filesSize).SetUnits(pb.U_BYTES)
progressBar.Start()
defer progressBar.FinishPrint("update successful!")
r := body
reader := progressBar.NewProxyReader(r)
err = update.Apply(reader, update.Options{})
if err != nil {
displayhelpers.Failf("update failed: %s", err)
}
return nil
}