diff --git a/main.go b/main.go index b901a3f..d85b98b 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "sync" + "time" ) //go:embed tools.json @@ -57,6 +58,8 @@ func main() { sem := make(chan struct{}, *parallel) results := make(chan result, len(tf.Tools)) + startTime := time.Now() + for _, t := range tf.Tools { wg.Add(1) go func(tool Tool) { @@ -68,11 +71,12 @@ func main() { fmt.Printf("Installing %s@%s...\n", tool.Name, tool.Version) } + toolStart := time.Now() pkg := fmt.Sprintf("%s@%s", tool.Package, tool.Version) cmd := exec.Command("go", "install", pkg) cmd.Env = os.Environ() output, err := cmd.CombinedOutput() - results <- result{tool: tool, err: err, output: string(output)} + results <- result{tool: tool, err: err, output: string(output), duration: time.Since(toolStart)} }(t) } @@ -84,25 +88,34 @@ func main() { var succeeded, failed int for r := range results { if r.err != nil { - fmt.Printf("✗ %s@%s: %v\n", r.tool.Name, r.tool.Version, r.err) + fmt.Printf("✗ %s@%s: %v (%s)\n", r.tool.Name, r.tool.Version, r.err, formatDuration(r.duration)) if *verbose && r.output != "" { fmt.Printf(" %s\n", r.output) } failed++ } else { - fmt.Printf("✓ %s@%s\n", r.tool.Name, r.tool.Version) + fmt.Printf("✓ %s@%s (%s)\n", r.tool.Name, r.tool.Version, formatDuration(r.duration)) succeeded++ } } - fmt.Printf("\nDone: %d succeeded, %d failed\n", succeeded, failed) + totalDuration := time.Since(startTime) + fmt.Printf("\nDone: %d succeeded, %d failed in %s\n", succeeded, failed, formatDuration(totalDuration)) if failed > 0 { os.Exit(1) } } type result struct { - tool Tool - err error - output string + tool Tool + err error + output string + duration time.Duration +} + +func formatDuration(d time.Duration) string { + if d < time.Second { + return fmt.Sprintf("%dms", d.Milliseconds()) + } + return fmt.Sprintf("%.1fs", d.Seconds()) }