/
fetch.go
74 lines (64 loc) · 1.68 KB
/
fetch.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
package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
rootCmd.AddCommand(fetchCmd)
fetchCmd.Flags().BoolVarP(
&disableRecursion,
"single-stage",
"s",
false,
"don't operate recursively over Stage inputs",
)
}
type noRemoteError struct{}
func (e noRemoteError) Error() string {
return "no remote specified in the config"
}
var fetchCmd = &cobra.Command{
Use: "fetch [flags] [stage_file]...",
Short: "Fetch committed artifacts from the remote cache",
Long: `Fetch downloads previously committed artifacts from a remote cache.
For each stage passed in, fetch downloads the stage's committed outputs from the
remote cache specified in the Dud config file. If no stage files are passed
in, fetch will act on all stages in the index. By default, fetch will act
recursively on all stages upstream of the given stage(s).
This command requires rclone to be installed on your machine. Visit
https://rclone.org/ for more information and installation instructions.`,
Run: func(cmd *cobra.Command, paths []string) {
rootDir, ch, idx, err := prepare(paths)
if err != nil {
fatal(err)
}
remote := viper.GetString("remote")
if remote == "" {
fatal(noRemoteError{})
}
if len(paths) == 0 {
// Ignore disableRecursion flag when no args passed.
disableRecursion = false
for path := range idx {
paths = append(paths, path)
}
}
fetched := make(map[string]bool)
for _, path := range paths {
inProgress := make(map[string]bool)
if err := idx.Fetch(
path,
ch,
rootDir,
!disableRecursion,
remote,
fetched,
inProgress,
logger,
); err != nil {
fatal(err)
}
logger.Info.Println()
}
},
}