-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo.go
72 lines (63 loc) 路 1.3 KB
/
todo.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
64
65
66
67
68
69
70
71
72
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"github.com/tcd/prjr/internal/cli"
"github.com/tcd/prjr/internal/prjr"
)
var todoCmd = &cobra.Command{
Use: "todo",
Short: "List TODO comments in a project",
Run: func(cmd *cobra.Command, args []string) {
root, _ := cmd.Flags().GetString("root")
if root != "" {
todoFuncFlag(root)
}
todoFuncPrompt()
},
}
func init() {
rootCmd.AddCommand(todoCmd)
todoCmd.Flags().String("root", "", "Path to the root of the Project to search for TODOs")
}
func todoFuncPrompt() {
pjs, err := prjr.GetLocalProjects()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
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 {
todos := pj.TODOs()
fmt.Println(cli.TabTodos(todos))
}
}
os.Exit(0)
}
func todoFuncFlag(root string) {
pjs, err := prjr.GetLocalProjects()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if !filepath.IsAbs(root) {
fmt.Fprintln(os.Stderr, "Please provide an absolute path")
os.Exit(1)
}
pj, ok := pjs.FindByRoot(root)
if ok {
todos := pj.TODOs()
fmt.Println(cli.TabTodos(todos))
}
os.Exit(0)
}