parent
ece8baeaac
commit
91ff1a10d4
@ -1,23 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"os"
|
||||
|
||||
"git.yetaga.in/deltamualpha/libyear/pkg/gomod"
|
||||
"git.yetaga.in/deltamualpha/libyear/pkg/libyear"
|
||||
"git.yetaga.in/deltamualpha/libyear/pkg/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
pairs, err := gomod.LoadAndComputePairs("go.mod")
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
l.Error(err)
|
||||
os.Exit(255)
|
||||
}
|
||||
|
||||
for dep := range pairs {
|
||||
fmt.Printf("%s: %d years (newest version: %s)\n", pairs[dep].Name, libyear.Calc(pairs[dep]).Truncate(time.Hour)/time.Hour/8760, pairs[dep].Latest.Version)
|
||||
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: %d years\n", libyear.Calc(pairs...).Truncate(time.Hour)/time.Hour/8760)
|
||||
fmt.Printf("total libyear count: %s year(s)\n", libyear.DecimalYear(libyear.Calc(pairs...)))
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package libyear
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDecimalYear(t *testing.T) {
|
||||
values := map[time.Duration]string{
|
||||
time.Hour: "0.00",
|
||||
time.Hour * 8760: "1.00",
|
||||
time.Hour * 4380: "0.50",
|
||||
time.Hour * 12264: "1.40",
|
||||
time.Hour * 27520: "3.14",
|
||||
time.Hour * 1000000: "114.16",
|
||||
}
|
||||
for d, s := range values {
|
||||
if r := DecimalYear(d); r != s {
|
||||
t.Logf("Expected %s, got %s for %d", s, r, d)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Log struct {
|
||||
quiet bool
|
||||
debug bool
|
||||
errOut io.Writer
|
||||
stdOut io.Writer
|
||||
}
|
||||
|
||||
func NewLogger(quiet, debug bool, stdOut, errOut io.Writer) *Log {
|
||||
if stdOut == nil {
|
||||
stdOut = os.Stdout
|
||||
}
|
||||
if errOut == nil {
|
||||
errOut = os.Stderr
|
||||
}
|
||||
return &Log{
|
||||
quiet: quiet,
|
||||
debug: debug,
|
||||
stdOut: stdOut,
|
||||
errOut: errOut,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Log) Error(s ...interface{}) {
|
||||
fmt.Fprint(l.errOut, s...)
|
||||
}
|
||||
|
||||
func (l *Log) Errorf(f string, s ...interface{}) {
|
||||
fmt.Fprint(l.errOut, s...)
|
||||
}
|
||||
|
||||
func (l *Log) Log(s ...interface{}) {
|
||||
if !l.quiet {
|
||||
fmt.Fprint(l.stdOut, s...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Log) Logf(f string, s ...interface{}) {
|
||||
if !l.quiet {
|
||||
fmt.Fprintf(l.stdOut, f, s...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Log) Debug(s ...interface{}) {
|
||||
if l.debug {
|
||||
fmt.Fprint(l.errOut, s...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Log) Debugf(f string, s ...interface{}) {
|
||||
if l.debug {
|
||||
fmt.Fprintf(l.errOut, f, s...)
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
# libyear
|
||||
|
||||
A **simple** measure of software dependency freshness. It is a **single number** telling you how up-to-date your dependencies are.
|
||||
|
||||
[libyear.com](https://libyear.com/)
|
||||
|
||||
## Usage
|
||||
|
||||
`libyear` only supports projects using go modules. It ignores dependencies that are replaced in a go.mod file.
|
||||
|
||||
`-q`: quiet mode; reduce logging and output only dependencies that are not at their latest version
|
||||
|
||||
`-v`: verbose mode; output diagnostic information
|
||||
|
||||
`-indirect`: include dependencies marked `// indirect` in `go.mod` in the calculation (excluded by default)
|
||||
|
||||
## Example output
|
||||
|
||||
When run in a directory that contains a `go.mod` file:
|
||||
|
||||
```bash
|
||||
$ libyear
|
||||
github.com/pkg/errors: 1.03 year(s) (current: v0.8.1, newest: v0.9.1)
|
||||
github.com/stretchr/testify: 1.51 year(s) (current: v1.4.0, newest: v1.7.0)
|
||||
go.uber.org/atomic: 0.00 year(s) (up to date: v1.7.0)
|
||||
go.uber.org/multierr: 0.00 year(s) (up to date: v1.6.0)
|
||||
gopkg.in/yaml.v2: 2.01 year(s) (current: v2.2.2, newest: v2.4.0)
|
||||
total libyear count: 4.55 year(s)
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
J. Cox, E. Bouwers, M. van Eekelen and J. Visser, Measuring Dependency Freshness in Software Systems. In Proceedings of the 37th International Conference on Software Engineering (ICSE 2015), May 2015 <https://ericbouwers.github.io/papers/icse15.pdf>
|
Loading…
Reference in new issue