-
Notifications
You must be signed in to change notification settings - Fork 1
/
stat.go
48 lines (43 loc) 路 843 Bytes
/
stat.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
package cmd
import (
"fmt"
"os"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"github.com/tcd/prjr/internal/prjr"
)
var statCmd = &cobra.Command{
Use: "stat",
Short: "Print Git status information for a project",
Run: func(cmd *cobra.Command, args []string) {
projects, err := prjr.GetLocalProjects()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
statFunc(projects)
},
}
func init() {
rootCmd.AddCommand(statCmd)
}
func statFunc(pjs prjr.Projects) {
root := ""
prompt := &survey.Select{
Message: "Which project would you like to check on?",
Options: pjs.Roots(),
}
survey.AskOne(prompt, &root)
if root != "" {
pj, ok := pjs.FindByRoot(root)
if ok {
status, err := pj.GitStatus()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(status)
}
}
os.Exit(0)
}