libyear/main.go
2021-04-10 22:22:06 -04:00

57 lines
1.3 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"git.yetaga.in/alazyreader/libyear/pkg/gomod"
"git.yetaga.in/alazyreader/libyear/pkg/libyear"
"git.yetaga.in/alazyreader/libyear/pkg/logger"
)
func main() {
quiet := flag.Bool("q", false, "quiet; reduces logging and outputs only out-of-date dependencies")
verbose := flag.Bool("v", false, "verbose; outputs diagnostic information")
indirect := flag.Bool("indirect", false, "include indirect dependencies in calculation (off by default)")
flag.Parse()
l := logger.NewLogger(*quiet, *verbose, os.Stdout, os.Stderr)
g := gomod.GoMod{
IncludeIndirect: *indirect,
ProxyLoader: gomod.Queryer{Logger: l},
Logger: l,
}
pairs, err := g.LoadAndComputePairs("go.mod")
if err != nil {
l.Error(err)
os.Exit(255)
}
for dep := range pairs {
if pairs[dep].Current.Time == pairs[dep].Latest.Time {
if !*quiet {
fmt.Printf(
"%s: %s year(s) (up to date: %s)\n",
pairs[dep].Name,
libyear.DecimalYear(libyear.Calc(pairs[dep])),
pairs[dep].Latest.Version,
)
}
} else {
fmt.Printf(
"%s: %s year(s) (current: %s, newest: %s)\n",
pairs[dep].Name,
libyear.DecimalYear(libyear.Calc(pairs[dep])),
pairs[dep].Current.Version,
pairs[dep].Latest.Version,
)
}
}
fmt.Printf("total libyear count: %s year(s)\n", libyear.DecimalYear(libyear.Calc(pairs...)))
}