Skip to content

Commit 940992e

Browse files
authored
Better CLI UX (#8)
1 parent e7d7a42 commit 940992e

File tree

7 files changed

+10
-18
lines changed

7 files changed

+10
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The original implementation was started by [@quasilyte](https://github.com/quasi
2020
$ go get -u github.com/go-perf/go-perftuner
2121

2222
# Check installation (prints help):
23-
$ go-perftuner
23+
$ go-perftuner help
2424

2525
# Run almostInlined sub-command on strings and bytes package:
2626
$ go-perftuner almostInlined strings bytes

almostInlined.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"log"
76
"os/exec"
87
"regexp"
98
)
@@ -61,7 +60,7 @@ func (r *almostInlinedRunner) Run(pkg string) error {
6160
}
6261

6362
for _, r := range results {
64-
log.Printf("%s: %s: budget exceeded by %d\n", r.Loc, r.Fn, r.Diff)
63+
fmt.Printf("%s: %s: budget exceeded by %d\n", r.Loc, r.Fn, r.Diff)
6564
}
6665
return nil
6766
}

boundChecks.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"log"
65
"os/exec"
76
"regexp"
87
)
@@ -42,7 +41,7 @@ func (r *boundCheckRunner) Run(pkg string) error {
4241
}
4342

4443
for _, r := range results {
45-
log.Printf("%s: slice/array has bound checks\n", r.Loc)
44+
fmt.Printf("%s: slice/array has bound checks\n", r.Loc)
4645
}
4746
return nil
4847
}

escapeanalysis.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"log"
65
"os/exec"
76
"regexp"
87
)
@@ -47,7 +46,7 @@ func (r *escapeAnalysisRunner) Run(pkg string) error {
4746
}
4847

4948
for _, r := range results {
50-
log.Printf("%s: %s\n", r.Loc, r.Variable)
49+
fmt.Printf("%s: %s\n", r.Loc, r.Variable)
5150
}
5251
return nil
5352
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/go-perf/go-perftuner
22

33
go 1.10
44

5-
require github.com/cristalhq/acmd v0.3.0
5+
require github.com/cristalhq/acmd v0.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github.com/cristalhq/acmd v0.3.0 h1:P9/h5Mn5OlRCEu1+b7bFWMBPenC6LORwc76vpf/GK0E=
2-
github.com/cristalhq/acmd v0.3.0/go.mod h1:LG5oa43pE/BbxtfMoImHCQN++0Su7dzipdgBjMCBVDQ=
1+
github.com/cristalhq/acmd v0.5.0 h1:0bzePcUUuzazlaAJoZmDTnL9396RwqrdA16m5+LpBhY=
2+
github.com/cristalhq/acmd v0.5.0/go.mod h1:LG5oa43pE/BbxtfMoImHCQN++0Su7dzipdgBjMCBVDQ=

main.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"flag"
66
"fmt"
7-
"log"
87
"os"
98
"strings"
109

@@ -19,11 +18,6 @@ var (
1918
)
2019

2120
func main() {
22-
if len(os.Args) < 2 {
23-
panic("not enough arguments, expected sub-command name")
24-
}
25-
26-
log.SetFlags(0)
2721
flag.StringVar(&flagMod, "mod", "", `-mod compiler flag(readonly|vendor)`)
2822
flag.BoolVar(&asJSON, "json", false, `return result as JSON`)
2923
flag.Parse()
@@ -32,7 +26,8 @@ func main() {
3226
Version: version,
3327
})
3428
if err := r.Run(); err != nil {
35-
log.Fatal(fmt.Errorf("dbumper: %w", err))
29+
fmt.Printf("go-perf: %v\n", err)
30+
os.Exit(1)
3631
}
3732
}
3833

@@ -72,7 +67,7 @@ func run(cmd subCommandRunner) error {
7267
cmd.Init()
7368
for _, pkg := range flag.Args()[1:] {
7469
if err := cmd.Run(pkg); err != nil {
75-
log.Printf("%s: %v", pkg, err)
70+
fmt.Printf("%s: %v", pkg, err)
7671
}
7772
}
7873
return nil

0 commit comments

Comments
 (0)