-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_update.go
More file actions
111 lines (93 loc) · 3.24 KB
/
Copy pathcmd_update.go
File metadata and controls
111 lines (93 loc) · 3.24 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
var updateCmd = &cobra.Command{
Use: "update",
Short: "Update Grove project dependencies",
Long: bold("update") + ` updates the Grove project dependencies to their
latest versions and runs ` + colorCyan + `go mod tidy` + colorReset + ` to clean up the module graph.
Currently updates:
` + colorCyan + `github.com/caiolandgraf/gest/v2` + colorReset + ` — the testing library used by ` + colorGreen + `grove test` + colorReset + `
` + colorCyan + `github.com/caiolandgraf/gest/v2/cmd/gest` + colorReset + ` — the gest CLI binary (beautiful output)
` + colorGray + `Examples:` + colorReset + `
grove update`,
RunE: runUpdate,
}
func runUpdate(_ *cobra.Command, _ []string) error {
fmt.Println()
// ── gest library (go.mod) ─────────────────────────────────────────────────
fmt.Printf(
" %sUpdating gest library%s %s\n",
colorGray, colorReset,
gray("(go get "+gestModule+")"),
)
fmt.Println()
gestCmd := exec.Command("go", "get", gestModule)
gestCmd.Stdout = newIndentWriter(os.Stdout, " ")
gestCmd.Stderr = newIndentWriter(os.Stderr, " ")
if err := gestCmd.Run(); err != nil {
fmt.Println(warn("Failed to update gest."))
fmt.Printf(
" %sRun manually: %s\n",
colorGray,
colorGreen+"go get "+gestModule+colorReset,
)
fmt.Println()
return fmt.Errorf("go get %s: %w", gestModule, err)
}
fmt.Println(success("gest library updated"))
fmt.Println()
// ── gest CLI (global binary) ──────────────────────────────────────────────
fmt.Printf(
" %sUpdating gest CLI%s %s\n",
colorGray, colorReset,
gray("(go install "+gestCLIModule+")"),
)
fmt.Println()
gestCLICmd := exec.Command("go", "install", gestCLIModule)
gestCLICmd.Stdout = newIndentWriter(os.Stdout, " ")
gestCLICmd.Stderr = newIndentWriter(os.Stderr, " ")
if err := gestCLICmd.Run(); err != nil {
fmt.Println(
warn(
"Failed to install gest CLI — beautiful output will not be available.",
),
)
fmt.Printf(
" %sRun manually: %s\n",
colorGray,
colorGreen+"go install "+gestCLIModule+colorReset,
)
fmt.Println()
// Non-fatal: the CLI is optional, grove test falls back to go test.
} else {
fmt.Println(success("gest CLI updated"))
fmt.Println()
}
// ── go mod tidy ───────────────────────────────────────────────────────────
fmt.Printf(
" %sCleaning module graph%s %s\n",
colorGray, colorReset,
gray("(go mod tidy)"),
)
fmt.Println()
tidyCmd := exec.Command("go", "mod", "tidy")
tidyCmd.Stdout = newIndentWriter(os.Stdout, " ")
tidyCmd.Stderr = newIndentWriter(os.Stderr, " ")
if err := tidyCmd.Run(); err != nil {
fmt.Println(
warn("go mod tidy failed — your go.mod may need manual attention."),
)
fmt.Println()
return fmt.Errorf("go mod tidy: %w", err)
}
fmt.Println(success("go.mod tidied"))
fmt.Println()
fmt.Println(done("All dependencies are up to date."))
fmt.Println()
return nil
}