-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand_timeline.go
56 lines (49 loc) · 1.18 KB
/
command_timeline.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
package main
import (
"sort"
"time"
"github.com/urfave/cli"
ct "github.com/daviddengcn/go-colortext"
"github.com/dustin/go-humanize"
)
var flagsOfTimeline = []cli.Flag{
cli.BoolFlag{
Name: "short, s",
Usage: "shorten result for pipeline processing",
},
}
var commandTimeline = cli.Command{
Name: "timeline",
Action: doTimeline,
Flags: flagsOfTimeline,
}
func doTimeline(c *cli.Context) error {
ghqPath := verifyGhqPath()
reposChannel := searchForRepos(ghqPath)
// Sort by time
repos := []Repository{}
for repo := range reposChannel {
repos = append(repos, repo)
}
sort.Sort(RepositoriesByModTime{repos})
// Listing repos
for _, repo := range repos {
duration := time.Now().Sub(repo.ModTime).Hours()
var timeColor ct.Color
if duration > 4320 { // 6 months
timeColor = ct.Red
} else if duration > 2160 { // 3 months
timeColor = ct.Yellow
} else if duration > 720 { // 1 month
timeColor = ct.Green
} else if duration > 504 { // 3 weeks
timeColor = ct.Blue
} else if duration > 168 { // 1 week
timeColor = ct.Magenta
} else {
timeColor = ct.White
}
printlnWithColor(repo.Path+" ("+humanize.Time(repo.ModTime)+")", timeColor)
}
return nil
}