diff --git a/cmd/chroma/main.go b/cmd/chroma/main.go index b57fc3a..ff79929 100644 --- a/cmd/chroma/main.go +++ b/cmd/chroma/main.go @@ -44,9 +44,9 @@ command, for Go. Check bool `help:"Do not format, check for tokenization errors instead."` Filename string `help:"Filename to use for selecting a lexer when reading from stdin."` - Lexer string `help:"Lexer to use when formatting." placeholder:"autodetect" short:"l"` - Style string `help:"Style to use for formatting." default:"swapoff" short:"s"` - Formatter string `help:"Formatter to use." default:"terminal" short:"f"` + Lexer string `help:"Lexer to use when formatting." default:"autodetect" short:"l" enum:"${lexers}"` + Style string `help:"Style to use for formatting." default:"swapoff" short:"s" enum:"${styles}"` + Formatter string `help:"Formatter to use." default:"terminal" short:"f" enum:"${formatters}"` JSON bool `help:"Output JSON representation of tokens."` @@ -79,7 +79,10 @@ func (n *nopFlushableWriter) Flush() error { return nil } func main() { ctx := kong.Parse(&cli, kong.Description(description), kong.Vars{ - "version": fmt.Sprintf("%s-%s-%s", version, commit, date), + "version": fmt.Sprintf("%s-%s-%s", version, commit, date), + "lexers": "autodetect," + strings.Join(lexers.Names(true), ","), + "styles": strings.Join(styles.Names(), ","), + "formatters": strings.Join(formatters.Names(), ","), }) if cli.List { listAll() @@ -246,7 +249,7 @@ func lex(ctx *kong.Context, path string, contents string) chroma.Iterator { } func selexer(path, contents string) (lexer chroma.Lexer) { - if cli.Lexer != "" { + if cli.Lexer != "autodetect" { return lexers.Get(cli.Lexer) } if path != "" { diff --git a/go.mod b/go.mod index f664c66..281cf3e 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ require ( github.com/GeertJohan/go.rice v1.0.0 github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 // indirect - github.com/alecthomas/kong v0.1.15 - github.com/alecthomas/kong-hcl v0.1.7 + github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae + github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8 github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 // indirect github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 github.com/dlclark/regexp2 v1.1.6 diff --git a/go.sum b/go.sum index 66ffcc9..2638362 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,11 @@ github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VEN github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= github.com/alecthomas/go.rice v1.0.1-0.20190717041731-572a5da3dff8 h1:PyEz5JLcmLYoi+1CegL90Wm5qfx9pl62D/DeNRnmkdU= github.com/alecthomas/go.rice v1.0.1-0.20190717041731-572a5da3dff8/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4= -github.com/alecthomas/kong v0.1.13/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU= -github.com/alecthomas/kong v0.1.15 h1:IWBg+KrLvoHBicD50OzMI8fKjrtAa1okMR9g38HVM/s= -github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU= -github.com/alecthomas/kong-hcl v0.1.7 h1:BhqAe2mE/cBq7Plnb218eTonsp4KcXf0BZCu3bO3qxg= -github.com/alecthomas/kong-hcl v0.1.7/go.mod h1:+diJg0tzfMUY/5uDo0dlb7uThhVpWr59PuYkdtRJbms= +github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= +github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae h1:C4Q9m+oXOxcSWwYk9XzzafY2xAVAaeubZbUHJkw3PlY= +github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= +github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8 h1:atLL+K8Hg0e8863K2X+k7qu+xz3M2a/mWFIACAPf55M= +github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8/go.mod h1:MRgZdU3vrFd05IQ89AxUZ0aYdF39BYoNFa324SodPCA= github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY= github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY= @@ -37,9 +37,12 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=