cli: sort the results

Adds `FileCount` and `FileCountList` types for storing language file and
their count which can be sorted based on the value of count.

Signed-off-by: Sunny <me@darkowlzz.space>
This commit is contained in:
Sunny
2017-09-30 18:41:48 +05:30
parent ded6d367fe
commit b84e338f9e
3 changed files with 65 additions and 5 deletions

View File

@ -89,3 +89,17 @@ func IsBinary(data []byte) bool {
return true
}
// FileCount type stores language name and count of files belonging to the
// language.
type FileCount struct {
Name string
Count int
}
// FileCountList type is a list of FileCounts.
type FileCountList []FileCount
func (fcl FileCountList) Len() int { return len(fcl) }
func (fcl FileCountList) Less(i, j int) bool { return fcl[i].Count < fcl[j].Count }
func (fcl FileCountList) Swap(i, j int) { fcl[i], fcl[j] = fcl[j], fcl[i] }