-
Notifications
You must be signed in to change notification settings - Fork 5
/
sync.go
44 lines (33 loc) · 882 Bytes
/
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
package sncli
import (
"os"
"time"
"github.com/briandowns/spinner"
"github.com/gookit/color"
"github.com/jonhadfield/gosn-v2/cache"
)
func Sync(si cache.SyncInput, useStdErr bool) (so cache.SyncOutput, err error) {
if !si.Debug {
prefix := color.HiWhite.Sprintf("syncing ")
if _, err = os.Stat(si.Session.CacheDBPath); os.IsNotExist(err) {
prefix = color.HiWhite.Sprintf("initializing ")
}
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stdout))
if useStdErr {
s = spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr))
}
s.Prefix = prefix
s.Start()
so, err = sync(si)
s.Stop()
return
}
so, err = sync(si)
return
}
func sync(si cache.SyncInput) (so cache.SyncOutput, err error) {
return cache.Sync(cache.SyncInput{
Session: si.Session,
Close: si.Close,
})
}