2017-09-19 14:15:33 +10:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2017-09-29 21:59:52 +10:00
|
|
|
"os"
|
2017-09-19 14:15:33 +10:00
|
|
|
|
|
|
|
"github.com/alecthomas/chroma/formatters"
|
|
|
|
"github.com/alecthomas/chroma/lexers"
|
|
|
|
"github.com/alecthomas/chroma/styles"
|
|
|
|
"gopkg.in/alecthomas/kingpin.v3-unstable"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
filesArgs = kingpin.Arg("file", "Files to use to exercise lexers.").Required().ExistingFiles()
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
kingpin.CommandLine.Help = "Exercise linters against a list of files."
|
|
|
|
kingpin.Parse()
|
|
|
|
|
|
|
|
for _, file := range *filesArgs {
|
|
|
|
lexer := lexers.Match(file)
|
|
|
|
if lexer == nil {
|
|
|
|
fmt.Printf("warning: could not find lexer for %q\n", file)
|
|
|
|
continue
|
|
|
|
}
|
2017-09-29 21:59:52 +10:00
|
|
|
fmt.Printf("%s: ", file)
|
|
|
|
os.Stdout.Sync()
|
2017-09-19 14:15:33 +10:00
|
|
|
text, err := ioutil.ReadFile(file)
|
|
|
|
kingpin.FatalIfError(err, "")
|
2017-09-20 22:30:25 +10:00
|
|
|
it, err := lexer.Tokenise(nil, string(text))
|
2017-09-19 14:15:33 +10:00
|
|
|
kingpin.FatalIfError(err, "%s failed to tokenise %q", lexer.Config().Name, file)
|
2017-09-20 22:30:25 +10:00
|
|
|
err = formatters.NoOp.Format(ioutil.Discard, styles.SwapOff, it)
|
|
|
|
kingpin.FatalIfError(err, "%s failed to format %q", lexer.Config().Name, file)
|
2017-09-29 21:59:52 +10:00
|
|
|
fmt.Printf("ok\n")
|
2017-09-19 14:15:33 +10:00
|
|
|
}
|
|
|
|
}
|