/
communitypull.go
63 lines (51 loc) 路 1.52 KB
/
communitypull.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
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/robocorp/rcc/common"
"github.com/robocorp/rcc/operations"
"github.com/robocorp/rcc/pathlib"
"github.com/robocorp/rcc/pretty"
"github.com/spf13/cobra"
)
var (
branch string
)
var communityPullCmd = &cobra.Command{
Use: "pull",
Short: "Pull a robot from URL or community sources.",
Long: "Pull a robot from URL or community sources.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if common.DebugFlag() {
defer common.Stopwatch("Pull lasted").Report()
}
zipfile := filepath.Join(pathlib.TempDir(), fmt.Sprintf("pull%x.zip", common.When))
defer os.Remove(zipfile)
common.Debug("Using temporary zipfile at %v", zipfile)
var err error
branches := []string{branch, "master", "trunk", "main"}
for _, selected := range branches {
link := operations.CommunityLocation(args[0], selected)
err = operations.DownloadCommunityRobot(link, zipfile)
if err == nil {
break
}
}
if err != nil {
pretty.Exit(1, "Download failed: %v!", err)
}
err = operations.Unzip(directory, zipfile, true, false, true)
if err != nil {
pretty.Exit(1, "Error: %v", err)
}
pretty.Ok()
},
}
func init() {
communityCmd.AddCommand(communityPullCmd)
rootCmd.AddCommand(communityPullCmd)
communityPullCmd.Flags().StringVarP(&branch, "branch", "b", "main", "Branch/tag/commitid to use as basis for robot.")
communityPullCmd.Flags().StringVarP(&directory, "directory", "d", ".", "The root directory to extract the robot into.")
}