Compare commits

..

No commits in common. "7ed7a548342822f2ed13cbee5908ad7f40f06d2d" and "3797df7022c9db0a131f93e12e28746bdbd008bf" have entirely different histories.

2 changed files with 6 additions and 16 deletions

View File

@ -4,8 +4,6 @@ CLI for [caniuse](https://caniuse.com)
Retrieves data from the [repository](https://github.com/Fyrd/caniuse) Retrieves data from the [repository](https://github.com/Fyrd/caniuse)
Largely based off of [caniuse-cmd](https://github.com/sgentle/caniuse-cmd), with fewer flags.
## License ## License
[MIT](LICENSE) [MIT](LICENSE)

20
main.go
View File

@ -128,23 +128,16 @@ func formatFeat(feat data, d Data, short bool) string {
} }
needNote := make(map[int]struct{}) needNote := make(map[int]struct{})
browsers := make([]string, 0, len(feat.Stats)) for browser, stats := range feat.Stats {
for browser := range feat.Stats {
if d.Agents[browser].Type != "desktop" { if d.Agents[browser].Type != "desktop" {
continue continue
} }
browsers = append(browsers, browser)
}
sort.Strings(browsers)
for _, browser := range browsers {
agent := d.Agents[browser]
stats := feat.Stats[browser]
if !short { if !short {
out.WriteString("\t") out.WriteString("\t")
} }
out.WriteString(agent.Browser + " ") out.WriteString(d.Agents[browser].Browser + " ")
results := makeResults(agent, stats) results := makeResults(d.Agents[browser], stats)
if len(results) == 1 { if len(results) == 1 {
results[0].version = "" results[0].version = ""
} }
@ -172,10 +165,10 @@ func formatFeat(feat data, d Data, short bool) string {
if _, ok := needNote[n]; !ok { if _, ok := needNote[n]; !ok {
continue continue
} }
out.WriteString(fmt.Sprintf("\t%s%s\n", color.YellowString(supernums[n]), feat.NotesByNum[num])) out.WriteString(fmt.Sprintf("\t\t%s%s\n", color.YellowString(supernums[n]), feat.NotesByNum[num]))
} }
if feat.Notes != "" { if feat.Notes != "" {
out.WriteString(fmt.Sprintf("\t%s %s", resultmap["i"], replaceNoteRe.ReplaceAllString(feat.Notes, " "))) out.WriteString(fmt.Sprintf("\t %s %s", resultmap["i"], replaceNoteRe.ReplaceAllString(feat.Notes, " ")))
} }
} }
@ -213,7 +206,7 @@ func makeResult(stat browserStat, nums map[int]struct{}) string {
} }
out.WriteString(fmt.Sprintf("(%f) ", math.Round(stat.usage*1)/1)) out.WriteString(fmt.Sprintf("(%f) ", math.Round(stat.usage*1)/1))
} }
out.WriteString(" ") out.WriteString(" ")
str := out.String() str := out.String()
switch support { switch support {
@ -283,7 +276,6 @@ func loadData() (Data, error) {
if err != nil && !errors.Is(err, fs.ErrNotExist) { if err != nil && !errors.Is(err, fs.ErrNotExist) {
return data, fmt.Errorf("could not stat %q: %v", dataPath, err) return data, fmt.Errorf("could not stat %q: %v", dataPath, err)
} else if errors.Is(err, fs.ErrNotExist) || time.Since(fi.ModTime()) > refresh { } else if errors.Is(err, fs.ErrNotExist) || time.Since(fi.ModTime()) > refresh {
color.Blue("updating caniuse data...")
if err := Download(dataPath); err != nil { if err := Download(dataPath); err != nil {
return data, fmt.Errorf("could not download data: %v", err) return data, fmt.Errorf("could not download data: %v", err)
} }