Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,26 @@ statloc project_name/
```

```
+-------------+-------+-------+
| Item | LOC | Files |
+-------------+-------+-------+
| Go | 2339 | 27 |
| Python | 10398 | 112 |
| Rust | 970 | 11 |
| Tests | 4612 | 43 |
| Total | 13737 | 155 |
+-------------+-------+-------+
🗣️ Languages
+--------+-----+-------+
| Title | LOC | Files |
+--------+-----+-------+
| Python | 4 | 2 |
| C++ | 8 | 2 |
| Rust | 8 | 2 |
| Go | 8 | 1 |
+--------+-----+-------+

⚡ Components
+-------------+-----+-------+
| Title | LOC | Files |
+-------------+-----+-------+
| Tests | 10 | 3 |
| Controllers | 8 | 2 |
+-------------+-----+-------+

📊 Total statistics
Languages: 4 LOC: 28 Files 7

```

Expand Down
9 changes: 5 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
Here's a list of versions of the project are
currently being supported with security updates.


| Version | Supported |
| ------- | ------------------ |
| 0.1 | :white_check_mark: |
| Version | Supported |
| ------- | --------- |
| 0.1 | ❌ |
| 0.2 | ✅ |
| 0.3 | ✅ |

#### ‼️ Reporting a Vulnerability

Expand Down
15 changes: 5 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ import (
"fmt"
"os"

core "github.com/statloc/core"

"cli/internal"
)

func main () {
if len(os.Args) != 2 {
if len(os.Args) > 2 {
fmt.Println("Error parsing argument: path specified incorrectly")
} else {
path := os.Args[1]
response, err := core.GetStatistics(path)

if err != nil {
fmt.Printf("ERROR: path \"%s\" is not found!!!\n", path)
} else {
fmt.Print(internal.GetTable(response.Items, 5, 3, 5))
path := "."
if len(os.Args) == 2 {
path = os.Args[1]
}
fmt.Print(internal.Respond(path))
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module cli
go 1.25.1

require (
github.com/statloc/core v0.1.1
github.com/statloc/core v0.3.0
github.com/stretchr/testify v1.11.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ=
github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI=
github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YEwQ0=
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
github.com/statloc/core v0.1.1 h1:P14Zwr1335qsjrwb5r5vtN9VQMhhPCccN3pVraQ5ooY=
github.com/statloc/core v0.1.1/go.mod h1:wSaKZ/WZpoghw/PGmI54rBb5PfBxoESkRH2EesFUrn0=
github.com/statloc/core v0.3.0 h1:tJbgDGe5fvGt4tsmb0cKaAEV5VSGenJ61SrDdrAC2Xs=
github.com/statloc/core v0.3.0/go.mod h1:wSaKZ/WZpoghw/PGmI54rBb5PfBxoESkRH2EesFUrn0=
github.com/stbenjam/no-sprintf-host-port v0.2.0 h1:i8pxvGrt1+4G0czLr/WnmyH7zbZ8Bg8etvARQ1rpyl4=
github.com/stbenjam/no-sprintf-host-port v0.2.0/go.mod h1:eL0bQ9PasS0hsyTyfTjjG+E80QIyPnBVQbYZyv20Jfk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
25 changes: 25 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ import (
core "github.com/statloc/core"
)

func Respond(path string) (result string) {
response, err := core.GetStatistics(path)

if err != nil {
return fmt.Sprintf("ERROR: path \"%s\" is not found!!!\n", path)
}

result = fmt.Sprintf(
`🗣️ Languages
%s
⚡ Components
%s
📊 Total statistics
Languages: %d LOC: %d Files %d
`,
GetTable(response.Languages, 5, 3, 5),
GetTable(response.Components, 5, 3, 5),
len(response.Languages),
response.Total.LOC,
response.Total.Files,
)

return
}

func GetTable(
items map[string]*core.TableItem,
titleLength int,
Expand Down
17 changes: 15 additions & 2 deletions internal/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetTable(t *testing.T) {
func TestRespond(t *testing.T) {
file, _ := os.Open("../testdata/results.txt")
defer file.Close() // nolint:errcheck

response := internal.Respond("../testdata")

// go line by line
scanner := bufio.NewScanner(file)
for scanner.Scan() {
assert.True(t, strings.Contains(response, scanner.Text()))
}
}

func TestGetTable(t *testing.T) {
file, _ := os.Open("../testdata/languages.txt")
defer file.Close() // nolint:errcheck

statistics, _ := core.GetStatistics("../testdata")
table := internal.GetTable(statistics.Items, 5, 3, 5)
table := internal.GetTable(statistics.Languages, 5, 3, 5)

// go line by line
scanner := bufio.NewScanner(file)
Expand Down
8 changes: 8 additions & 0 deletions testdata/languages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
+--------+-----+-------+
| Title | LOC | Files |
+--------+-----+-------+
| Rust | 8 | 2 |
| Go | 8 | 1 |
| Python | 4 | 2 |
| C++ | 8 | 2 |
+--------+-----+-------+
19 changes: 15 additions & 4 deletions testdata/results.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
🗣️ Languages
+--------+-----+-------+
| Title | LOC | Files |
+--------+-----+-------+
| Tests | 6 | 2 |
| Rust | 4 | 1 |
| Rust | 8 | 2 |
| Go | 8 | 1 |
| Python | 2 | 1 |
| Total | 24 | 4 |
| Python | 4 | 2 |
| C++ | 8 | 2 |
+--------+-----+-------+

⚡ Components
+-------------+-----+-------+
| Title | LOC | Files |
+-------------+-----+-------+
| Tests | 10 | 3 |
| Controllers | 8 | 2 |
+-------------+-----+-------+

📊 Total statistics
Languages: 4 LOC: 28 Files 7
3 changes: 3 additions & 0 deletions testdata/somedir/controllers/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}
1 change: 1 addition & 0 deletions testdata/somedir/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")
3 changes: 3 additions & 0 deletions testdata/somedir/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World!");
}
3 changes: 3 additions & 0 deletions testdata/tests/controllers/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}