Merge pull request #70 from mcarmonaa/fix/document-safe

documented safe value and plural functions in the README
This commit is contained in:
Alfredo Beaumont 2017-07-11 10:26:38 +02:00 committed by GitHub
commit c6e4c7f41c

View File

@ -22,15 +22,15 @@ 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
@ -38,6 +38,21 @@ fmt.Println(lang)
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
-----------------