/
mutagen-status.go
62 lines (55 loc) · 1.75 KB
/
mutagen-status.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 (
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/globalconfig"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
"github.com/spf13/cobra"
)
// MutagenStatusCmd implements the ddev mutagen status command
var MutagenStatusCmd = &cobra.Command{
Use: "status",
Short: "Shows mutagen sync status",
Aliases: []string{"st"},
Example: `"ddev mutagen status", "ddev mutagen status <projectname>"`,
Run: func(cmd *cobra.Command, args []string) {
projectName := ""
verbose := false
if len(args) > 1 {
util.Failed("This command only takes one optional argument: project-name")
}
if len(args) == 1 {
projectName = args[0]
}
if cmd.Flags().Changed("verbose") {
verbose = true
}
app, err := ddevapp.GetActiveApp(projectName)
if err != nil {
util.Failed("Failed to get active project: %v", err)
}
if !(app.IsMutagenEnabled()) {
util.Warning("Mutagen is not enabled on project %s", app.Name)
return
}
status, shortResult, _, err := app.MutagenStatus()
if err != nil {
util.Failed("unable to get mutagen status for project %s, output='%s': %v", app.Name, shortResult, err)
}
ok := "Mutagen: " + status
resultOut := shortResult
if verbose {
fullResult, err := exec.RunHostCommand(globalconfig.GetMutagenPath(), "sync", "list", "-l", ddevapp.MutagenSyncName(app.Name))
if err != nil {
util.Failed("unable to get mutagen status for project %s, output='%s': %v", app.Name, fullResult, err)
}
resultOut = "\n" + fullResult
}
output.UserOut.Printf("%s: %s", ok, resultOut)
},
}
func init() {
MutagenCmd.AddCommand(MutagenStatusCmd)
MutagenStatusCmd.Flags().BoolP("verbose", "l", false, "Extended/verbose output for mutagen status")
}