50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Nim
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Nim
		
	
	
	
	
	
import std/logging, std/strutils
 | 
						|
import docopt
 | 
						|
 | 
						|
import pco_chordspkg/ast, pco_chordspkg/cliconstants, pco_chordspkg/html
 | 
						|
 | 
						|
when isMainModule:
 | 
						|
 try:
 | 
						|
  let consoleLogger = newConsoleLogger(
 | 
						|
    levelThreshold=lvlInfo,
 | 
						|
    fmtStr="pco_chords - $levelname: ",
 | 
						|
    useStderr=true)
 | 
						|
  logging.addHandler(consoleLogger)
 | 
						|
 | 
						|
  # Parse arguments
 | 
						|
  let args = docopt(USAGE, version = PCO_CHORDSVERSION)
 | 
						|
 | 
						|
  if args["--debug"]:
 | 
						|
    consoleLogger.levelThreshold = lvlDebug
 | 
						|
 | 
						|
  if args["--echo-args"]: stderr.writeLine($args)
 | 
						|
 | 
						|
  if args["help"]:
 | 
						|
    stderr.writeLine(USAGE & "\n")
 | 
						|
    stderr.writeLine(ONLINE_HELP)
 | 
						|
    quit()
 | 
						|
 | 
						|
  let inputText =
 | 
						|
    if args["--input"]: readFile($args["--input"])
 | 
						|
    else: readAll(stdin)
 | 
						|
 | 
						|
  let ast = parseChordChart(inputText)
 | 
						|
  debug "Parsed AST\p" &
 | 
						|
    "-".repeat(16) & "\p" &
 | 
						|
    $ast & "\p" &
 | 
						|
    "-".repeat(16) & "\p"
 | 
						|
 | 
						|
  let transpose =
 | 
						|
    if args["--transpose"]: parseInt($args["--transpose"])
 | 
						|
    else: 0
 | 
						|
 | 
						|
  let outputHtml = ast.toHtml(transpose, args["--number-chart"])
 | 
						|
 | 
						|
  if args["--output"]: writeFile($args["--output"], outputHtml)
 | 
						|
  else: stdout.write(outputHtml)
 | 
						|
 | 
						|
 except CatchableError:
 | 
						|
  fatal getCurrentExceptionMsg()
 | 
						|
  debug getCurrentException().getStackTrace()
 | 
						|
  quit(QuitFailure)
 |