forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
62 lines (52 loc) · 1.33 KB
/
get.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
package cmd
import (
"fmt"
"os"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/yaoapp/yao/cmd/get"
"github.com/yaoapp/yao/share"
)
var getCmd = &cobra.Command{
Use: "get",
Short: L("Get an application"),
Long: L("Get an application"),
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println(color.RedString(L("Not enough arguments")))
fmt.Println(color.WhiteString(share.BUILDNAME + " help"))
return
}
repo := args[0]
pkg, err := get.New(repo)
if err != nil {
fmt.Println(color.RedString(err.Error()))
os.Exit(1)
}
fmt.Println(color.WhiteString("From Infra: %s", pkg.Remote))
fmt.Println(color.WhiteString("Visit: https://LetsInfra.com"))
err = pkg.Download()
if err != nil {
fmt.Println(color.RedString(err.Error()))
os.Exit(1)
}
dest, err := os.Getwd()
if err != nil {
fmt.Println(color.RedString(err.Error()))
os.Exit(1)
}
// dest, err = os.MkdirTemp(dest, "*-unit-test")
// if err != nil {
// fmt.Println(color.RedString(err.Error()))
// os.Exit(1)
// }
// os.MkdirAll(dest, os.ModePerm)
app, err := pkg.Unpack(dest)
if err != nil {
fmt.Println(color.RedString(err.Error()))
os.Exit(1)
}
fmt.Println(color.GreenString(app.Name), color.WhiteString(app.Version))
fmt.Println(color.GreenString(L("✨DONE✨")))
},
}