github.com/driusan/bug@v0.3.2-0.20190306121946-d7f4e7f33fea/bugapp/Roadmap.go (about) 1 package bugapp 2 3 import ( 4 "fmt" 5 "github.com/blang/semver" 6 "github.com/driusan/bug/bugs" 7 "sort" 8 "strconv" 9 "strings" 10 ) 11 12 type BugListByMilestone [](bugs.Bug) 13 14 func (a BugListByMilestone) Len() int { return len(a) } 15 func (a BugListByMilestone) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 16 func (a BugListByMilestone) Less(i, j int) bool { 17 iMS := a[i].Milestone() 18 jMS := a[j].Milestone() 19 // If there's a "v" at the start, strip it out 20 // before doing any comparisons of semantic 21 // versions 22 if len(iMS) > 1 && iMS[0] == "v"[0] { 23 iMS = iMS[1:] 24 } 25 if len(jMS) > 1 && jMS[0] == "v"[0] { 26 jMS = jMS[1:] 27 } 28 // First try semantic versioning comparison 29 iVer, iVerErr := semver.Make(iMS) 30 jVer, jVerErr := semver.Make(jMS) 31 if iVerErr == nil && jVerErr == nil { 32 return iVer.LT(jVer) 33 } 34 35 // Next try floating point comparison as an 36 // approximation of real number comparison.. 37 iFloat, iVerErr := strconv.ParseFloat(iMS, 32) 38 jFloat, jVerErr := strconv.ParseFloat(jMS, 32) 39 if iVerErr == nil && jVerErr == nil { 40 return iFloat < jFloat 41 } 42 43 // Finally, just use a normal string collation 44 return iMS < jMS 45 } 46 47 func Roadmap(args ArgumentList) { 48 var bgs []bugs.Bug 49 50 if args.HasArgument("--filter") { 51 tags := strings.Split(args.GetArgument("--filter", ""), ",") 52 fmt.Printf("%s", tags) 53 bgs = bugs.FindBugsByTag(tags) 54 } else { 55 bgs = bugs.GetAllBugs() 56 } 57 sort.Sort(BugListByMilestone(bgs)) 58 59 fmt.Printf("# Roadmap for %s\n", bugs.GetRootDir().GetShortName().ToTitle()) 60 milestone := "" 61 for i := len(bgs) - 1; i >= 0; i -= 1 { 62 b := bgs[i] 63 newMilestone := b.Milestone() 64 if milestone != newMilestone { 65 if newMilestone == "" { 66 fmt.Printf("\n## No milestone set:\n") 67 } else { 68 fmt.Printf("\n## %s:\n", newMilestone) 69 } 70 } 71 if args.HasArgument("--simple") { 72 fmt.Printf("- %s\n", b.Title("")) 73 } else { 74 options := "" 75 if !args.HasArgument("--no-status") { 76 options += "status" 77 } 78 if !args.HasArgument("--no-priority") { 79 options += " priority" 80 } 81 if !args.HasArgument("--no-identifier") { 82 options += " identifier" 83 } 84 85 if args.HasArgument("--tags") { 86 options += "tags" 87 } 88 fmt.Printf("- %s\n", b.Title(options)) 89 } 90 milestone = newMilestone 91 92 } 93 }