/
holotreePull.go
50 lines (45 loc) 路 1.67 KB
/
holotreePull.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
package cmd
import (
"github.com/robocorp/rcc/common"
"github.com/robocorp/rcc/htfs"
"github.com/robocorp/rcc/operations"
"github.com/robocorp/rcc/pretty"
"github.com/spf13/cobra"
)
var (
remoteOriginOption string
pullRobot string
forcePull bool
)
var holotreePullCmd = &cobra.Command{
Use: "pull",
Short: "Try to pull existing holotree catalog from remote source.",
Long: "Try to pull existing holotree catalog from remote source.",
Run: func(cmd *cobra.Command, args []string) {
if common.DebugFlag() {
defer common.Stopwatch("Holotree pull command lasted").Report()
}
_, holotreeBlueprint, err := htfs.ComposeFinalBlueprint(nil, pullRobot)
pretty.Guard(err == nil, 1, "Blueprint calculation failed: %v", err)
hash := common.BlueprintHash(holotreeBlueprint)
tree, err := htfs.New()
pretty.Guard(err == nil, 2, "%s", err)
present := tree.HasBlueprint(holotreeBlueprint)
if !present || forcePull {
catalog := htfs.CatalogName(hash)
err = operations.PullCatalog(remoteOriginOption, catalog, true)
pretty.Guard(err == nil, 3, "%s", err)
}
pretty.Ok()
},
}
func init() {
origin := common.RccRemoteOrigin()
holotreeCmd.AddCommand(holotreePullCmd)
holotreePullCmd.Flags().BoolVarP(&forcePull, "force", "", false, "Force pull check, even when blueprint is already present.")
holotreePullCmd.Flags().StringVarP(&remoteOriginOption, "origin", "o", origin, "URL of remote origin to pull environment from.")
holotreePullCmd.Flags().StringVarP(&pullRobot, "robot", "r", "robot.yaml", "Full path to 'robot.yaml' configuration file to export as catalog. <optional>")
if len(origin) == 0 {
holotreePullCmd.MarkFlagRequired("origin")
}
}