forked from kevin-hanselman/dud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.go
79 lines (70 loc) · 1.75 KB
/
checkout.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
package cmd
import (
"github.com/kevin-hanselman/dud/src/strategy"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(checkoutCmd)
checkoutCmd.Flags().BoolVarP(
&useCopyStrategy,
"copy",
"c",
false,
"copy artifacts instead of linking",
)
checkoutCmd.Flags().BoolVarP(
&disableRecursion,
"single-stage",
"s",
false,
"disable recursive operation on upstream stages",
)
}
var useCopyStrategy, disableRecursion bool
var checkoutCmd = &cobra.Command{
Use: "checkout [flags] [stage_file]...",
Short: "Load committed artifacts from the cache",
Long: `Checkout loads previously committed artifacts from the cache.
For each stage file passed in, checkout makes the stage's output artifacts
available in the workspace. By default, checkout creates symlinks to the cache,
but copies of the cached artifacts can be checked out using --copy. If no
stage files are passed in, checkout will act on all stages in the index. By
default, checkout will act recursively on all stages upstream of the given
stage(s).`,
Run: func(cmd *cobra.Command, paths []string) {
strat := strategy.LinkStrategy
if useCopyStrategy {
strat = strategy.CopyStrategy
}
rootDir, ch, idx, err := prepare(paths...)
if err != nil {
fatal(err)
}
if len(idx) == 0 {
fatal(emptyIndexError{})
}
if len(paths) == 0 {
// Ignore disableRecursion flag when no args passed.
disableRecursion = false
for path := range idx {
paths = append(paths, path)
}
}
checkedOut := make(map[string]bool)
for _, path := range paths {
inProgress := make(map[string]bool)
if err := idx.Checkout(
path,
ch,
rootDir,
strat,
!disableRecursion,
checkedOut,
inProgress,
logger,
); err != nil {
fatal(err)
}
}
},
}