trending/main.go

51 lines
1.1 KiB
Go

package main
import (
"flag"
"os"
"github.com/caarlos0/log"
"github.com/charmbracelet/lipgloss"
)
var Version = "develop"
func main() {
fs := flag.NewFlagSet("trending", flag.ExitOnError)
versionFlag := fs.Bool("version", false, "Show version and exit")
fs.BoolVar(versionFlag, "v", *versionFlag, "--version")
if err := fs.Parse(os.Args[1:]); err != nil {
log.WithError(err).Error("")
return
}
if *versionFlag {
log.Infof("trending (%s)", Version)
return
}
cfg, err := loadConfig()
if err != nil {
log.WithError(err).Error("could not load config")
}
for _, lang := range cfg.Languages {
l, err := trendingLang(lang.Name, lang.Timeframes)
if err != nil {
log.WithError(err).Fatal("could not get trending repositories")
}
log.Styles[log.InfoLevel] = lipgloss.NewStyle().Foreground(lipgloss.Color(l.color)).Bold(true)
log.Info(lang.Name)
log.IncreasePadding()
for _, repo := range l.repositories {
log.WithField("link", repo.link()).Info(repo.name)
if repo.description != "" {
log.IncreasePadding()
log.Info(repo.description)
log.DecreasePadding()
}
}
log.ResetPadding()
}
}