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 ``` diff --git a/SECURITY.md b/SECURITY.md index 34e2974..eae8f5b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -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 diff --git a/cmd/main.go b/cmd/main.go index 97c1acc..30a4fb5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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)) } } diff --git a/go.mod b/go.mod index 7bd6d05..c352919 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.3.0 github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index febaf49..b837a57 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.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= diff --git a/internal/utils.go b/internal/utils.go index e7ee504..403c02d 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -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, diff --git a/internal/utils_test.go b/internal/utils_test.go index 710efe5..380a72c 100644 --- a/internal/utils_test.go +++ b/internal/utils_test.go @@ -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) 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; +}