From 6eaf447b5eb00e9e3f716a3872f427de05e4f3c8 Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Tue, 9 Jun 2020 10:38:36 +0200 Subject: [PATCH 1/4] doc: update usage doc Signed-off-by: Alexander Bezzubov --- README.md | 16 ++++++++++++---- main.go | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e5992a1..98f7d24 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,18 @@ $ enry Note that enry's CLI **_does not need an actual git repository to work_**, which is an intentional difference from linguist. +## Usage -Install -------- +By default, only the languages from Markdown and Programming groups are reported. + +One can choose to report all the languages (including plain text, configuration scripts, etc) using +``` +enry -all +``` + +Well-known vendoring, configuration, documentation paths as well as paths starting with dot are alwasy excluded from the final report. + +## Install The recommended way to install the `enry` command-line tool is to either [download a release](https://github.com/go-enry/enry/releases) or run: @@ -30,7 +39,6 @@ The recommended way to install the `enry` command-line tool is to either (cd "$(mktemp -d)" && go mod download && go get github.com/go-enry/enry) ``` -License -------- +## License Apache License, Version 2.0. See [LICENSE](LICENSE) diff --git a/main.go b/main.go index 86792ce..6b2236c 100644 --- a/main.go +++ b/main.go @@ -147,9 +147,9 @@ func main() { const usageFormat = `enry, a simple (and faster) implementation of github/linguist -usage: %[1]s [-mode=(file|line|byte)] [-prog] - %[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown] - %[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown] +usage: %[1]s [-mode=(file|line|byte)] [-all] [-prog] + %[1]s [-mode=(file|line|byte)] [-all] [-json] [-breakdown] + %[1]s [-mode=(file|line|byte)] [-all] [-json] [-breakdown] %[1]s [-version] build info: %[2]s, commit: %[3]s, based on linguist commit: %[4]s From 47dc1e1a0556c41f2af65f2ef1b1a389261fe35b Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Tue, 9 Jun 2020 10:44:46 +0200 Subject: [PATCH 2/4] Fixes #4 by adding -prog flag to keep only the programming languages Signed-off-by: Alexander Bezzubov --- README.md | 7 ++++++- main.go | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98f7d24..da51014 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,16 @@ Note that enry's CLI **_does not need an actual git repository to work_**, which By default, only the languages from Markdown and Programming groups are reported. -One can choose to report all the languages (including plain text, configuration scripts, etc) using +One can choose to report all the languages (including plain text, markup, templates, configuration scripts, etc) using ``` enry -all ``` +For cases when subsequent lexing/parsing of the files is desired, one can keep only the programming languages by +``` +enry -prog +``` + Well-known vendoring, configuration, documentation paths as well as paths starting with dot are alwasy excluded from the final report. ## Install diff --git a/main.go b/main.go index 6b2236c..4d84b11 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { jsonFlag := flag.Bool("json", false, "") showVersion := flag.Bool("version", false, "Show the enry version information") allLangs := flag.Bool("all", false, "Show all files, including those identifed as non-programming languages") + progLangs := flag.Bool("prog", false, "Show only files identifed as programming languages only") countMode := flag.String("mode", "byte", "the method used to count file size. Available options are: file, line and byte") limitKB := flag.Int64("limit", 16*1024, "Analyse first N KB of the file (-1 means no limit)") flag.Parse() @@ -112,6 +113,9 @@ func main() { return nil } + if *progLangs && enry.GetLanguageType(language) != enry.Programming { + return nil + } // If we are not asked to display all, do as // https://github.com/github/linguist/blob/bf95666fc15e49d556f2def4d0a85338423c25f3/lib/linguist/blob_helper.rb#L382 if !*allLangs && @@ -131,7 +135,7 @@ func main() { var buf bytes.Buffer switch { case *jsonFlag && !*breakdownFlag: - printJson(out, &buf) + printJSON(out, &buf) case *jsonFlag && *breakdownFlag: printBreakDown(out, &buf) case *breakdownFlag: @@ -148,8 +152,8 @@ func main() { const usageFormat = `enry, a simple (and faster) implementation of github/linguist usage: %[1]s [-mode=(file|line|byte)] [-all] [-prog] - %[1]s [-mode=(file|line|byte)] [-all] [-json] [-breakdown] - %[1]s [-mode=(file|line|byte)] [-all] [-json] [-breakdown] + %[1]s [-mode=(file|line|byte)] [-all] [-prog] [-json] [-breakdown] + %[1]s [-mode=(file|line|byte)] [-all] [-prog] [-json] [-breakdown] %[1]s [-version] build info: %[2]s, commit: %[3]s, based on linguist commit: %[4]s @@ -174,7 +178,7 @@ func printBreakDown(out map[string][]string, buff *bytes.Buffer) { } } -func printJson(out map[string][]string, buf *bytes.Buffer) { +func printJSON(out map[string][]string, buf *bytes.Buffer) { json.NewEncoder(buf).Encode(out) } From 2210db25f1934d16a088261c5eac6f4004e530e0 Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Tue, 9 Jun 2020 11:27:33 +0200 Subject: [PATCH 3/4] bump go-enry to the latest v2.5.2 Signed-off-by: Alexander Bezzubov --- go.mod | 2 +- go.sum | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 3263317..dc918fc 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/go-enry/enry go 1.14 -require github.com/go-enry/go-enry/v2 v2.2.0 +require github.com/go-enry/go-enry/v2 v2.5.2 diff --git a/go.sum b/go.sum index 395a9d8..1e49bd5 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,14 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-enry/go-enry/v2 v2.2.0 h1:TSHIcu33jGdq7wld3UwO+WwfmckrrnPST7JZ+McjvHI= -github.com/go-enry/go-enry/v2 v2.2.0/go.mod h1:+xFJwbqWi15bvqFHb2ELUWVRKFQtwB61+sDrkvvxxGI= -github.com/go-enry/go-oniguruma v1.2.0 h1:oBO9XC1IDT9+AoWW5oFsa/7gFeOPacEqDbyXZKWXuDs= -github.com/go-enry/go-oniguruma v1.2.0/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4= +github.com/go-enry/go-enry/v2 v2.5.2 h1:3f3PFAO6JitWkPi1GQ5/m6Xu4gNL1U5soJ8QaYqJ0YQ= +github.com/go-enry/go-enry/v2 v2.5.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ= +github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo= +github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/toqueteos/trie v1.0.0 h1:8i6pXxNUXNRAqP246iibb7w/pSFquNTQ+uNfriG7vlk= -github.com/toqueteos/trie v1.0.0/go.mod h1:Ywk48QhEqhU1+DwhMkJ2x7eeGxDHiGkAdc9+0DYcbsM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/toqueteos/substring.v1 v1.0.2 h1:urLqCeMm6x/eTuQa1oZerNw8N1KNOIp5hD5kGL7lFsE= -gopkg.in/toqueteos/substring.v1 v1.0.2/go.mod h1:Eb2Z1UYehlVK8LYW2WBVR2rwbujsz3aX8XDrM1vbNew= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 918a04944f30743dcdaf951e55e26de354685fba Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Tue, 9 Jun 2020 11:33:08 +0200 Subject: [PATCH 4/4] Fixes #3 by filtering files using new .IsGenerated() Signed-off-by: Alexander Bezzubov --- main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4d84b11..3d76f89 100644 --- a/main.go +++ b/main.go @@ -84,8 +84,8 @@ func main() { } if enry.IsVendor(relativePath) || enry.IsDotFile(relativePath) || - enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) { - // TODO(bzz): skip enry.IsGeneratedPath() after https://github.com/src-d/enry/issues/213 + enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) || + enry.IsGenerated(relativePath, nil) { if f.IsDir() { return filepath.SkipDir } @@ -106,7 +106,10 @@ func main() { log.Println(err) return nil } - // TODO(bzz): skip enry.IsGeneratedContent() as well, after https://github.com/src-d/enry/issues/213 + + if enry.IsGenerated(relativePath, content) { + return nil + } language := enry.GetLanguage(filepath.Base(path), content) if language == enry.OtherLanguage {