use(require(“atomy”))

require(“anatomy/version”) require(“optparse”)

$LOAD_PATH unshift(File expand-path(“../../lib”, __FILE__))

processor = require(“anatomy/processor”)

options = #{

.input -> nil
.output -> "."
.renderer -> "html"
.serve -> nil
.version -> false

}

op = OptionParser new [o]:

o banner = "usage: anatomy [options]"

o on("-s", "--serve PORT", "serve the rendered documents on the given port") [v]:
  options[.serve] = v to-i

o on("-i", "--input FILE", "anatomy document") [v]:
  options[.input] = v

o on("-o", "--output DIRECTORY",
     "where to place output documents and files") [v]:
  options[.output] = v

o on("-r", "--renderer NAME",
     "which renderer to use (e.g. html)") [v]:
  options[.renderer] = v

o on-tail("--version", "print the version of anatomy and exit"):
  options[.version] = true

op parse!

when(options):

puts(Anatomy VERSION)
exit(0)

input = options output = options renderer = options

unless(input):

puts(op help)
exit(1)

– a / in the renderer name implies it's external unless(renderer include?(“/”)):

renderer = i"anatomy/renderers/#{renderer}"

if(options)

then:
  server = require("anatomy/server") Server new(
    options[.input]
    options[.output]
    processor
    require(renderer)
  )

  server serve(options[.serve])
else:
  processor process(input, require(renderer), output)