File: main.go

package info (click to toggle)
golang-github-alecthomas-chroma 0.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,652 kB
  • sloc: python: 426; javascript: 79; makefile: 34; sh: 32
file content (38 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"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
		}
		fmt.Printf("%s: ", file)
		os.Stdout.Sync()
		text, err := ioutil.ReadFile(file)
		kingpin.FatalIfError(err, "")
		it, err := lexer.Tokenise(nil, string(text))
		kingpin.FatalIfError(err, "%s failed to tokenise %q", lexer.Config().Name, file)
		err = formatters.NoOp.Format(ioutil.Discard, styles.SwapOff, it)
		kingpin.FatalIfError(err, "%s failed to format %q", lexer.Config().Name, file)
		fmt.Printf("ok\n")
	}
}