/
options.go
172 lines (143 loc) · 4.29 KB
/
options.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package local
import (
cid "github.com/ipfs/go-cid"
)
type newOptions struct {
name string
private bool
fromCid cid.Cid
strategy InitStrategy
events chan<- Event
unfreeze bool
}
// NewOption is used when creating a new bucket.
type NewOption func(*newOptions)
// WithName sets a name for the bucket.
func WithName(name string) NewOption {
return func(args *newOptions) {
args.name = name
}
}
// WithPrivate specifies that an encryption key will be used for the bucket.
func WithPrivate(private bool) NewOption {
return func(args *newOptions) {
args.private = private
}
}
// WithCid indicates an inited bucket should be boostraped with a particular UnixFS DAG.
func WithCid(c cid.Cid) NewOption {
return func(args *newOptions) {
args.fromCid = c
}
}
// WithUnfreeze indicates that the bucket should be bootstrapped from Filecoin.
func WithUnfreeze(enabled bool) NewOption {
return func(args *newOptions) {
args.unfreeze = enabled
}
}
// InitStrategy describes the type of init strategy.
type InitStrategy int
const (
// Hybrid indicates locally staged changes should be accepted, excluding deletions.
Hybrid InitStrategy = iota
// Soft indicates locally staged changes should be accepted, including deletions.
Soft
// Hard indicates locally staged changes should be discarded.
Hard
)
// WithStrategy allows for selecting the init strategy. Hybrid is the default.
func WithStrategy(strategy InitStrategy) NewOption {
return func(args *newOptions) {
args.strategy = strategy
}
}
// WithInitEvents allows the caller to receive events when pulling
// files from an existing bucket on initialization.
func WithInitEvents(ch chan<- Event) NewOption {
return func(args *newOptions) {
args.events = ch
}
}
type pathOptions struct {
confirm ConfirmDiffFunc
force bool
hard bool
events chan<- Event
}
// PathOption is used when pushing or pulling bucket paths.
type PathOption func(*pathOptions)
// ConfirmDiffFunc is a caller-provided function which presents a list of bucket changes.
type ConfirmDiffFunc func([]Change) bool
// WithConfirm allows the caller to confirm a list of bucket changes.
func WithConfirm(f ConfirmDiffFunc) PathOption {
return func(args *pathOptions) {
args.confirm = f
}
}
// WithForce indicates all remote files should be pulled even if they already exist.
func WithForce(b bool) PathOption {
return func(args *pathOptions) {
args.force = b
}
}
// WithHard indicates locally staged changes should be discarded.
func WithHard(b bool) PathOption {
return func(args *pathOptions) {
args.hard = b
}
}
// WithEvents allows the caller to receive events when pushing or pulling files.
func WithEvents(ch chan<- Event) PathOption {
return func(args *pathOptions) {
args.events = ch
}
}
type addOptions struct {
merge SelectMergeFunc
events chan<- Event
}
// SelectMergeFunc is a caller-provided function which is used to select a merge strategy.
type SelectMergeFunc func(description string, isDir bool) (MergeStrategy, error)
// MergeStrategy describes the type of path merge strategy.
type MergeStrategy string
const (
// Skip skips the path merge.
Skip MergeStrategy = "Skip"
// Merge attempts to merge the paths (directories only).
Merge = "Merge"
// Replace replaces the old path with the new path.
Replace = "Replace"
)
// AddOption is used when staging a remote Unixfs dag cid in a local bucket.
type AddOption func(*addOptions)
// WithSelectMerge allows the caller to select the path merge strategy.
func WithSelectMerge(f SelectMergeFunc) AddOption {
return func(args *addOptions) {
args.merge = f
}
}
// WithAddEvents allows the caller to receive events when staging files from a remote Unixfs dag.
func WithAddEvents(ch chan<- Event) AddOption {
return func(args *addOptions) {
args.events = ch
}
}
type watchOptions struct {
offline bool
events chan<- Event
}
// WatchOption is used when watching a bucket for changes.
type WatchOption func(*watchOptions)
// WithOffline will keep watching for bucket changes while the local network is offline.
func WithOffline(offline bool) WatchOption {
return func(args *watchOptions) {
args.offline = offline
}
}
// WithWatchEvents allows the caller to receive events when watching a bucket for changes.
func WithWatchEvents(ch chan<- Event) WatchOption {
return func(args *watchOptions) {
args.events = ch
}
}