Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI facelift: new option and filtering generated #5

Merged
merged 4 commits into from
Jun 15, 2020
Merged
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
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ $ 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, 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
bzz marked this conversation as resolved.
Show resolved Hide resolved
```

Well-known vendoring, configuration, documentation paths as well as paths starting with dot are alwasy excluded from the final report.
bzz marked this conversation as resolved.
Show resolved Hide resolved

## 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:
Expand All @@ -30,7 +44,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)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -83,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
}
Expand All @@ -105,13 +106,19 @@ 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 {
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 &&
Expand All @@ -131,7 +138,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:
Expand All @@ -147,9 +154,9 @@ func main() {

const usageFormat = `enry, a simple (and faster) implementation of github/linguist

usage: %[1]s [-mode=(file|line|byte)] [-prog] <path>
%[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown] <path>
%[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown]
usage: %[1]s [-mode=(file|line|byte)] [-all] [-prog] <path>
%[1]s [-mode=(file|line|byte)] [-all] [-prog] [-json] [-breakdown] <path>
%[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
Expand All @@ -174,7 +181,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)
}

Expand Down