From 751ad49f4e15a91fe44cd79be77468eb78051306 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Sat, 18 Oct 2025 13:43:20 +0300 Subject: [PATCH 1/3] support core@v0.2.0 --- SECURITY.md | 2 +- cmd/main.go | 16 +--------------- go.mod | 2 +- go.sum | 4 ++-- internal/utils.go | 31 +++++++++++++++++++++++++++++++ internal/utils_test.go | 2 +- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 34e2974..11b3333 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,7 +8,7 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| 0.1 | :white_check_mark: | +| 0.2 | :white_check_mark: | #### ‼️ Reporting a Vulnerability diff --git a/cmd/main.go b/cmd/main.go index 97c1acc..4e605ab 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,24 +2,10 @@ package main import ( "fmt" - "os" - - core "github.com/statloc/core" "cli/internal" ) func main () { - 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)) - } - } + fmt.Print(internal.Respond()) } diff --git a/go.mod b/go.mod index 7bd6d05..c270490 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module cli go 1.25.1 require ( - github.com/statloc/core v0.1.1 + github.com/statloc/core v0.2.0 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index febaf49..df74f10 100644 --- a/go.sum +++ b/go.sum @@ -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.2.0 h1:VjFxY42HONSXEK7L6g51RoMU5bWelkgKQYV4U/jyVE8= +github.com/statloc/core v0.2.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= diff --git a/internal/utils.go b/internal/utils.go index e7ee504..b8a217f 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -2,12 +2,43 @@ package internal import ( "fmt" + "os" "strconv" "strings" core "github.com/statloc/core" ) +func Respond() string { + if len(os.Args) != 2 { + return "Error parsing argument: path specified incorrectly" + } else { + path := os.Args[1] + 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 result + } +} + func GetTable( items map[string]*core.TableItem, titleLength int, diff --git a/internal/utils_test.go b/internal/utils_test.go index 710efe5..84df49d 100644 --- a/internal/utils_test.go +++ b/internal/utils_test.go @@ -16,7 +16,7 @@ func TestGetTable(t *testing.T) { 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) From 1966898e1d7f61a85699d4e2a0c5ff9c38a77ead Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Sat, 18 Oct 2025 13:59:01 +0300 Subject: [PATCH 2/3] fix --- cmd/main.go | 8 +++++++- internal/utils.go | 12 +++--------- internal/utils_test.go | 17 ++++++++++++++++- testdata/languages.txt | 8 ++++++++ testdata/results.txt | 19 +++++++++++++++---- testdata/somedir/controllers/main.cpp | 3 +++ testdata/somedir/main.py | 1 + testdata/somedir/main.rs | 3 +++ testdata/tests/controllers/main.cpp | 3 +++ 9 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 testdata/languages.txt create mode 100644 testdata/somedir/controllers/main.cpp create mode 100644 testdata/somedir/main.py create mode 100644 testdata/somedir/main.rs create mode 100644 testdata/tests/controllers/main.cpp diff --git a/cmd/main.go b/cmd/main.go index 4e605ab..f19cab5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,10 +2,16 @@ package main import ( "fmt" + "os" "cli/internal" ) func main () { - fmt.Print(internal.Respond()) + if len(os.Args) != 2 { + fmt.Println("Error parsing argument: path specified incorrectly") + } else { + path := os.Args[1] + fmt.Print(internal.Respond(path)) + } } diff --git a/internal/utils.go b/internal/utils.go index b8a217f..403c02d 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -2,25 +2,20 @@ package internal import ( "fmt" - "os" "strconv" "strings" core "github.com/statloc/core" ) -func Respond() string { - if len(os.Args) != 2 { - return "Error parsing argument: path specified incorrectly" - } else { - path := os.Args[1] +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( + result = fmt.Sprintf( `🗣️ Languages %s ⚡ Components @@ -35,8 +30,7 @@ Languages: %d LOC: %d Files %d response.Total.Files, ) - return result - } + return } func GetTable( diff --git a/internal/utils_test.go b/internal/utils_test.go index 84df49d..cfa47e6 100644 --- a/internal/utils_test.go +++ b/internal/utils_test.go @@ -11,16 +11,31 @@ 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() { + println(response, scanner.Text()) + 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.Languages, 5, 3, 5) // go line by line scanner := bufio.NewScanner(file) for scanner.Scan() { + println(table, scanner.Text()) assert.True(t, strings.Contains(table, scanner.Text())) } } diff --git a/testdata/languages.txt b/testdata/languages.txt new file mode 100644 index 0000000..0059cbb --- /dev/null +++ b/testdata/languages.txt @@ -0,0 +1,8 @@ ++--------+-----+-------+ +| Title | LOC | Files | ++--------+-----+-------+ +| Rust | 8 | 2 | +| Go | 8 | 1 | +| Python | 4 | 2 | +| C++ | 8 | 2 | ++--------+-----+-------+ diff --git a/testdata/results.txt b/testdata/results.txt index 93bb3e9..5a6b04e 100644 --- a/testdata/results.txt +++ b/testdata/results.txt @@ -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 diff --git a/testdata/somedir/controllers/main.cpp b/testdata/somedir/controllers/main.cpp new file mode 100644 index 0000000..33c14ce --- /dev/null +++ b/testdata/somedir/controllers/main.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/testdata/somedir/main.py b/testdata/somedir/main.py new file mode 100644 index 0000000..f1a1813 --- /dev/null +++ b/testdata/somedir/main.py @@ -0,0 +1 @@ +print("Hello world!") diff --git a/testdata/somedir/main.rs b/testdata/somedir/main.rs new file mode 100644 index 0000000..47ad8c6 --- /dev/null +++ b/testdata/somedir/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello World!"); +} diff --git a/testdata/tests/controllers/main.cpp b/testdata/tests/controllers/main.cpp new file mode 100644 index 0000000..33c14ce --- /dev/null +++ b/testdata/tests/controllers/main.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; +} From d1d423c80f303f9bafe6b97d3f84d53bcf5dbee0 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Sat, 18 Oct 2025 13:59:51 +0300 Subject: [PATCH 3/3] update readme --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 347b02a..f084a29 100644 --- a/README.md +++ b/README.md @@ -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 ```