nimpretty: implement a --maxLineLen command line option
This commit is contained in:
parent
eaf4b42ff9
commit
5bf3734984
2 changed files with 12 additions and 7 deletions
|
|
@ -18,7 +18,7 @@ import ../compiler / [idents, msgs, ast, syntaxes, renderer, options,
|
|||
import parseopt, strutils, os
|
||||
|
||||
const
|
||||
Version = "0.1"
|
||||
Version = "0.2"
|
||||
Usage = "nimpretty - Nim Pretty Printer Version " & Version & """
|
||||
|
||||
(c) 2017 Andreas Rumpf
|
||||
|
|
@ -28,6 +28,7 @@ Options:
|
|||
--output:file set the output file (default: overwrite the input file)
|
||||
--indent:N[=0] set the number of spaces that is used for indentation
|
||||
--indent:0 means autodetection (default behaviour)
|
||||
--maxLineLen:N set the desired maximum line length (default: 80)
|
||||
--version show the version
|
||||
--help show this help
|
||||
"""
|
||||
|
|
@ -45,6 +46,7 @@ proc writeVersion() =
|
|||
type
|
||||
PrettyOptions = object
|
||||
indWidth: int
|
||||
maxLineLen: int
|
||||
|
||||
proc prettyPrint(infile, outfile: string, opt: PrettyOptions) =
|
||||
var conf = newConfigRef()
|
||||
|
|
@ -55,6 +57,7 @@ proc prettyPrint(infile, outfile: string, opt: PrettyOptions) =
|
|||
var p: TParsers
|
||||
p.parser.em.indWidth = opt.indWidth
|
||||
if setupParsers(p, fileIdx, newIdentCache(), conf):
|
||||
p.parser.em.maxLineLen = opt.maxLineLen
|
||||
discard parseAll(p)
|
||||
closeParsers(p)
|
||||
|
||||
|
|
@ -66,6 +69,7 @@ proc main =
|
|||
# if input is not actually over-written, when nimpretty is a noop).
|
||||
# --backup was un-documented (rely on git instead).
|
||||
var opt: PrettyOptions
|
||||
opt.maxLineLen = 80
|
||||
for kind, key, val in getopt():
|
||||
case kind
|
||||
of cmdArgument:
|
||||
|
|
@ -77,6 +81,7 @@ proc main =
|
|||
of "backup": backup = parseBool(val)
|
||||
of "output", "o": outfile = val
|
||||
of "indent": opt.indWidth = parseInt(val)
|
||||
of "maxlinelen": opt.maxLineLen = parseInt(val)
|
||||
else: writeHelp()
|
||||
of cmdEnd: assert(false) # cannot happen
|
||||
if infile.len == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue