Skip to content

Commit

Permalink
Merge pull request #70 from mcarmonaa/fix/document-safe
Browse files Browse the repository at this point in the history
documented safe value and plural functions in the README
  • Loading branch information
abeaumont authored Jul 11, 2017
2 parents 4c28f19 + b2d0e59 commit c6e4c7f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,37 @@ Examples
--------

```go
lang, _ := GetLanguageByExtension("foo.go")
lang, safe := enry.GetLanguageByExtension("foo.go")
fmt.Println(lang)
// result: Go

lang, _ = GetLanguageByContent("foo.m", "<matlab-code>")
lang, safe := enry.GetLanguageByContent("foo.m", "<matlab-code>")
fmt.Println(lang)
// result: Matlab

lang, _ = GetLanguageByContent("bar.m", "<objective-c-code>")
lang, safe := enry.GetLanguageByContent("bar.m", "<objective-c-code>")
fmt.Println(lang)
// result: Objective-C

// all strategies together
lang := enry.GetLanguage("foo.cpp", "<cpp-code>")
```

Note the returned boolean value "safe" is set either to true, if there is only one possible language detected or, to false otherwise.

To get a list of possible languages for a given file, you can use the plural version of the detecting functions.

```go
langs := enry.GetLanguages("foo.h", "<cpp-code>")
// result: []string{"C++", "C"}

langs := enry.GetLanguagesByExtension("foo.asc", "<content>", nil)
// result: []string{"AGS Script", "AsciiDoc", "Public Key"}

langs := enry.GetLanguagesByFilename("Gemfile", "<content>", []string{})
// result: []string{"Ruby"}
```


CLI
-----------------
Expand Down

0 comments on commit c6e4c7f

Please sign in to comment.