Skip to content

Commit ddb5c49

Browse files
authored
CHORE: 0.1.0 pre-release (#2)
1 parent 23a8043 commit ddb5c49

File tree

9 files changed

+134
-12
lines changed

9 files changed

+134
-12
lines changed

β€Ž.github/workflows/check.ymlβ€Ž

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@ on:
99

1010
jobs:
1111
test:
12-
name: test-${{ matrix.os }}-go${{ matrix.go-version }}
12+
name: test-${{ matrix.os }}
1313
runs-on: ${{ matrix.os }}
1414
strategy:
1515
matrix:
16-
go-version:
17-
- "1.25"
18-
- "1.24"
1916
os:
2017
- "ubuntu-latest"
2118
- "windows-latest"
2219
- "macos-latest"
23-
2420
steps:
2521
- name: checkout
2622
uses: actions/checkout@v5
2723
- name: setup go
2824
uses: actions/setup-go@v5
2925
with:
30-
go-version: ${{ matrix.go-version }
26+
go-version: 1.25
3127
- name: run tests
3228
run: go test ./...

β€ŽREADME.mdβ€Ž

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
- Simple and fast
1414

1515
### ⚑ Installation
16-
As a go tool
16+
Via `go install`
1717
```shell
18-
go get -tool github.com/statloc/cli
18+
go install github.com/statloc/cli
1919
```
2020

2121
### πŸ“ Usage
@@ -28,13 +28,9 @@ statloc project_name/
2828
| Item | LOC | Files |
2929
+-------------+-------+-------+
3030
| Go | 2339 | 27 |
31-
+-------------+-------+-------+
3231
| Python | 10398 | 112 |
33-
+-------------+-------+-------+
3432
| Rust | 970 | 11 |
35-
+-------------+-------+-------+
3633
| Tests | 4612 | 43 |
37-
+-------------+-------+-------+
3834
| Total | 13737 | 155 |
3935
+-------------+-------+-------+
4036

β€Žcmd/main.goβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
core "github.com/statloc/core"
8+
9+
"cli/internal"
10+
)
11+
12+
func main () {
13+
if len(os.Args) != 2 {
14+
fmt.Println("Error parsing argument: path specified incorrectly")
15+
} else {
16+
path := os.Args[1]
17+
response, err := core.GetStatistics(path)
18+
19+
if err != nil {
20+
fmt.Printf("Path %s is not found\n", path)
21+
}
22+
23+
fmt.Print(internal.GetTable(response.Items))
24+
}
25+
}

β€Žinternal/utils.goβ€Ž

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package internal
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
core "github.com/statloc/core"
9+
)
10+
11+
func GetTable(items map[string]*core.TableItem) string {
12+
// im sorry for that
13+
maxTitleLength, maxLOCLength, maxFilesLength := 5, 3, 5
14+
for title, item := range items {
15+
if len(title) > maxTitleLength {
16+
maxTitleLength = len(title)
17+
}
18+
19+
LOC := strconv.FormatUint(item.LOC, 10)
20+
if len(LOC) > maxLOCLength {
21+
maxLOCLength = len(LOC)
22+
}
23+
24+
files := strconv.FormatUint(item.Files, 10)
25+
if len(files) > maxFilesLength {
26+
maxFilesLength = len(files)
27+
}
28+
}
29+
30+
separator := fmt.Sprintf(
31+
"+-%s-+-%s-+-%s-+\n",
32+
strings.Repeat("-", maxTitleLength),
33+
strings.Repeat("-", maxLOCLength),
34+
strings.Repeat("-", maxFilesLength),
35+
)
36+
37+
result := fmt.Sprint(
38+
separator,
39+
fmt.Sprintf(
40+
"| Title%s | LOC%s | Files%s |\n",
41+
strings.Repeat(" ", maxTitleLength - 5),
42+
strings.Repeat(" ", maxLOCLength - 3),
43+
strings.Repeat(" ", maxFilesLength - 5),
44+
),
45+
separator,
46+
)
47+
48+
for title, item := range items {
49+
result += fmt.Sprintf(
50+
"| %s%s | %d%s | %d%s |\n",
51+
title, strings.Repeat(" ", maxTitleLength - len(title)),
52+
item.LOC, strings.Repeat(" ", maxLOCLength - len(strconv.FormatUint(item.LOC, 10))),
53+
item.Files, strings.Repeat(" ", maxFilesLength - len(strconv.FormatUint(item.Files, 10))),
54+
)
55+
}
56+
57+
result += separator
58+
return result
59+
}

β€Žinternal/utils_test.goβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package internal_test
2+
3+
import (
4+
"bufio"
5+
"cli/internal"
6+
"os"
7+
"strings"
8+
"testing"
9+
10+
core "github.com/statloc/core"
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestGetTable(t *testing.T) {
15+
file, _ := os.Open("../testdata/results.txt")
16+
defer file.Close() // nolint:errcheck
17+
18+
statistics, _ := core.GetStatistics("../testdata")
19+
table := internal.GetTable(statistics.Items)
20+
21+
// go line by line
22+
scanner := bufio.NewScanner(file)
23+
for scanner.Scan() {
24+
assert.True(t, strings.Contains(table, scanner.Text()))
25+
}
26+
}

β€Žtestdata/main.goβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello, World!")
7+
}

β€Žtestdata/results.txtβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+--------+-----+-------+
2+
| Title | LOC | Files |
3+
+--------+-----+-------+
4+
| Tests | 6 | 2 |
5+
| Rust | 4 | 1 |
6+
| Go | 8 | 1 |
7+
| Python | 2 | 1 |
8+
| Total | 24 | 4 |
9+
+--------+-----+-------+

β€Žtestdata/tests/main.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello world!")

β€Žtestdata/tests/main.rsβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello World!");
3+
}

0 commit comments

Comments
Β (0)