Skip to content

Commit a144853

Browse files
authored
feat: modernize codebase (#5)
* feat: modernize codebase BREAKING CHANGE: introducing version 2 * fix: istanbul types
1 parent ebe06c3 commit a144853

File tree

15 files changed

+163
-748
lines changed

15 files changed

+163
-748
lines changed

.github/workflows/go.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
- name: Test
2626
run: go test -v
2727

28-
- name: Coverage
29-
uses: paambaati/codeclimate-action@v3.0.0
30-
env:
31-
CC_TEST_REPORTER_ID: 7442645f3d316d873958dd124e244c15cef0e7a11b1506f68932a04e472b58b5
32-
with:
33-
prefix: github.com/farbodsalimi/dokimi
34-
coverageCommand: go test -v --race -covermode=atomic -coverprofile=coverage.out ./...
35-
coverageLocations: ${{github.workspace}}/coverage.out:gocov
28+
# - name: Coverage
29+
# uses: paambaati/codeclimate-action@v3.0.0
30+
# env:
31+
# CC_TEST_REPORTER_ID: 7442645f3d316d873958dd124e244c15cef0e7a11b1506f68932a04e472b58b5
32+
# with:
33+
# prefix: github.com/farbodsalimi/dokimi
34+
# coverageCommand: go test -v --race -covermode=atomic -coverprofile=coverage.out ./...
35+
# coverageLocations: ${{github.workspace}}/coverage.out:gocov

CLAUDE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## What is Dokimi
6+
7+
Dokimi is a Go CLI tool that provides helper commands for Go test coverage:
8+
- **`report`** — Converts Go coverage profiles (`coverage.out`) to Istanbul JSON format, optionally opening an HTML report via the `istanbul` npm tool.
9+
- **`check-coverage`** — Checks total coverage against a threshold, failing (or warning) if below.
10+
11+
## Build & Test Commands
12+
13+
```bash
14+
go build ./... # build all packages
15+
go build -o ./bin/dokimi . # build binary
16+
go test ./... # run all tests
17+
go test -v -coverprofile=coverage.out ./... # tests with coverage
18+
go vet ./... # static analysis
19+
```
20+
21+
Makefile targets:
22+
```bash
23+
make # go build ./... (silent)
24+
make test # go test -v -coverprofile=coverage.out ./...
25+
make build # build binary to ./bin/dokimi
26+
make build-all # cross-compile for linux/darwin/windows amd64
27+
```
28+
29+
## Architecture
30+
31+
```
32+
main.go # entry point, sets Version via ldflags
33+
cmd/
34+
root.go # cobra root command, creates ~/.dokimi dirs on init
35+
report.go # "report" subcommand — delegates to reporter implementations
36+
check_coverage.go # "check-coverage" subcommand — shells out to `go tool cover`
37+
internal/
38+
configs/paths.go # global path constants (~/.dokimi/istanbul_tmp/*)
39+
reporters/istanbul/
40+
istanbul.go # Istanbul struct, types, functional options constructor
41+
write.go # WriteReport: parses Go cover profiles → Istanbul JSON
42+
show.go # ShowReport: writes JSON then runs `istanbul report` + `open`
43+
```
44+
45+
Key patterns:
46+
- Reporter uses **functional options** (`New(opts ...func(*Istanbul))`) with an injectable `writeFileFn` for testability.
47+
- Coverage parsing uses `golang.org/x/tools/cover.ParseProfiles`.
48+
- `ShowReport` depends on the `istanbul` npm package and macOS `open` command.
49+
- Version is injected at build time via `-ldflags="-X 'main.Version=vX.Y.Z'"`.

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.DEFAULT_GOAL := all
2+
3+
.PHONY: all test show-cover build build-all
4+
5+
all:
6+
@go build ./...
7+
8+
test:
9+
go test -v -coverprofile=coverage.out ./...
10+
11+
show-cover:
12+
dokimi report --input=coverage.out --output=coverage.json --reporter=istanbul --show
13+
14+
build:
15+
go build -o ./bin/dokimi github.com/farbodsalimi/dokimi
16+
17+
build-all:
18+
./scripts/build-all.sh github.com/farbodsalimi/dokimi

Taskfile.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

cmd/check_coverage.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ func NewCheckCoverageCmd() *cobra.Command {
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
result, err := exec.Command("go", "tool", "cover", "-func", coverProfile).Output()
2424
if err != nil {
25-
return err
25+
return fmt.Errorf("failed to run 'go tool cover' on %s: %w", coverProfile, err)
2626
}
2727

2828
content := string(result)
2929
index := strings.Index(content, "total")
30+
if index == -1 {
31+
return fmt.Errorf("could not find total coverage in %s", coverProfile)
32+
}
3033
line := content[index:]
3134
re := regexp.MustCompile(`([0-9]*\.?[0-9]*)\s*%`)
3235
match := re.FindStringSubmatch(line)
36+
if match == nil {
37+
return fmt.Errorf("could not parse coverage percentage from %s", coverProfile)
38+
}
3339
totalCoverage, err := strconv.ParseFloat(match[1], 32)
3440
if err != nil {
3541
return err
@@ -44,7 +50,7 @@ func NewCheckCoverageCmd() *cobra.Command {
4450
if doNotFail {
4551
log.Warn(msg)
4652
} else {
47-
log.Fatalf(msg)
53+
return fmt.Errorf("%s", msg)
4854
}
4955
}
5056

cmd/report.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@ package cmd
22

33
import (
44
"fmt"
5-
"strconv"
65

76
istanbulReporter "github.com/farbodsalimi/dokimi/internal/reporters/istanbul"
87
log "github.com/sirupsen/logrus"
98
"github.com/spf13/cobra"
109
)
1110

1211
func NewReportCmd() *cobra.Command {
13-
var reporter string
14-
var rInput string
15-
var rOutput string
16-
var show bool
12+
var (
13+
reporter string
14+
input string
15+
output string
16+
show bool
17+
)
1718

1819
reportCmd := &cobra.Command{
1920
Use: "report",
2021
Short: "Writes reports for Go coverage profiles",
2122
RunE: func(cmd *cobra.Command, args []string) error {
2223
log.Infof("Reporter:\t%s", reporter)
23-
log.Infof("Input:\t%s", rInput)
24-
log.Infof("Output:\t%s", rOutput)
25-
log.Infof("Show:\t%s", strconv.FormatBool(show))
24+
log.Infof("Input:\t%s", input)
25+
log.Infof("Output:\t%s", output)
26+
log.Infof("Show:\t%v", show)
2627

2728
switch reporter {
2829
case "istanbul":
@@ -32,26 +33,23 @@ func NewReportCmd() *cobra.Command {
3233
}
3334

3435
if show {
35-
istanbul.ShowReport(rInput, rOutput)
36-
} else {
37-
istanbul.WriteReport(rInput, rOutput)
36+
return istanbul.ShowReport(input, output)
3837
}
38+
return istanbul.WriteReport(input, output)
3939

4040
default:
4141
return fmt.Errorf("unknown reporter: %s", reporter)
4242
}
43-
44-
return nil
4543
},
4644
}
4745

4846
reportCmd.Flags().BoolVar(&show, "show", false, "Shows written reports")
4947
reportCmd.Flags().
5048
StringVarP(&reporter, "reporter", "r", "", "Reporter name e.g. istanbul, lcov, ...")
51-
reportCmd.Flags().StringVarP(&rInput, "input", "i", "", "Path to input file")
52-
reportCmd.Flags().StringVarP(&rOutput, "output", "o", "", "Path to output file")
49+
reportCmd.Flags().StringVarP(&input, "input", "i", "", "Path to input file")
50+
reportCmd.Flags().StringVarP(&output, "output", "o", "", "Path to output file")
5351
reportCmd.MarkFlagRequired("reporter")
54-
reportCmd.MarkFlagRequired("rInput")
52+
reportCmd.MarkFlagRequired("input")
5553

5654
return reportCmd
5755
}

go.mod

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
11
module github.com/farbodsalimi/dokimi
22

3-
go 1.18
3+
go 1.26
44

55
require (
66
github.com/mitchellh/go-homedir v1.1.0
77
github.com/olekukonko/tablewriter v0.0.5
88
github.com/sirupsen/logrus v1.8.1
99
github.com/spf13/cobra v1.4.0
10-
github.com/spf13/viper v1.11.0
11-
github.com/stretchr/testify v1.8.0
10+
golang.org/x/tools v0.43.0
1211
)
1312

1413
require (
15-
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/fsnotify/fsnotify v1.5.4 // indirect
17-
github.com/hashicorp/hcl v1.0.0 // indirect
1814
github.com/inconshreveable/mousetrap v1.0.0 // indirect
19-
github.com/magiconair/properties v1.8.6 // indirect
2015
github.com/mattn/go-runewidth v0.0.9 // indirect
21-
github.com/mitchellh/mapstructure v1.5.0 // indirect
22-
github.com/pelletier/go-toml v1.9.5 // indirect
23-
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
24-
github.com/pmezard/go-difflib v1.0.0 // indirect
25-
github.com/spf13/afero v1.8.2 // indirect
26-
github.com/spf13/cast v1.5.0 // indirect
27-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
2816
github.com/spf13/pflag v1.0.5 // indirect
29-
github.com/subosito/gotenv v1.2.0 // indirect
30-
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
31-
golang.org/x/text v0.3.7 // indirect
32-
gopkg.in/ini.v1 v1.66.4 // indirect
33-
gopkg.in/yaml.v2 v2.4.0 // indirect
34-
gopkg.in/yaml.v3 v3.0.1 // indirect
17+
github.com/stretchr/testify v1.8.0 // indirect
18+
golang.org/x/sys v0.42.0 // indirect
3519
)

0 commit comments

Comments
 (0)