-
Notifications
You must be signed in to change notification settings - Fork 63
/
strategy.go
67 lines (55 loc) · 2.31 KB
/
strategy.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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package packmanager
import "fmt"
// MergeStrategy is a method to describe how to approach creating packages that
// have the same canonical name. This is useful when deciding whether an
// existing package simply needs to be updated to include additional artifacts,
// e.g. targets, or whether the package should be overwritten because it is no
// longer required.
type MergeStrategy string
const (
// The 'exit' strategy is used to error-out and indicate that no strategy was
// provided and that further operations cannot be completed.
StrategyExit = MergeStrategy("exit")
// The 'overwrite' strategy removes the existing package with the same
// canonical name and replaces it with a new package entirely.
StrategyOverwrite = MergeStrategy("overwrite")
// The 'merge' strategy attempts to combine an existing package with new
// artifacts such the updated package contains the artifacts from before plus
// the artifacts.
//
// This is useful in contexts, for example, where packages represents an
// application which has multiple targets and a new target is added to the
// already packaged application.
StrategyMerge = MergeStrategy("merge")
// The 'prompt' strategy is an "unlisted" strategy that's used in TTY contexts
// where the user is given the opportunity to decide the merge strategy before
// the package operation is performed. The result of this decision should
// yield one of the above merge strategies.
StrategyPrompt = MergeStrategy("prompt")
)
var _ fmt.Stringer = (*MergeStrategy)(nil)
// String implements fmt.Stringer
func (strategy MergeStrategy) String() string {
return string(strategy)
}
// MergeStrategies returns the list of possible package merge strategies.
func MergeStrategies() []MergeStrategy {
return []MergeStrategy{
StrategyExit,
StrategyOverwrite,
StrategyMerge,
}
}
// MergeStrategyNames returns the string representation of all possible
// package merge strategies.
func MergeStrategyNames() []string {
strategies := []string{}
for _, strategy := range MergeStrategies() {
strategies = append(strategies, strategy.String())
}
return strategies
}