(local { : flatten : create-corpus } (require :src.story)) (fn show-help [] (print "Usage: tbls [options]") (print) (print "Basic Options:") (print " -h|--help print this message and exit") (print " -v|--version print version and exit") (print " -i|--input name of input file") (print " -k|--origin-table-key name of a table in the input file") (print " -s|--origin-table-string a string template") (print) (print "You must specify an input file") (print "You must specify either a string or a key to serve as an origin")) (fn parse-args [t] (if (= 0 (length t)) (do (show-help) (os.exit 0))) (fn inner [t opts] (if (= 0 (length t)) opts (do (case t (where [a] (or (= a "-h") (= a "--help"))) (do (show-help) (os.exit 0)) (where [a] (or (= a "-v") (= a "--version"))) (let [handle (io.popen "recsel doc/meta.rec -P version") result (handle:read "*a")] (print result) (handle:close) (os.exit 0)) (where [a input] (or (= a "-i") (= a "--input"))) (set opts.input input) (where [a key] (or (= a "-k") (= a "--origin-table-key"))) (set opts.key key) (where [a str] (or (= a "-s") (= a "--origin-table-string"))) (set opts.string str)) (let [next-t (icollect [i v (ipairs t)] (if (> i 2) v))] (inner next-t opts))))) (inner t {})) (fn main [] (let [opts (parse-args arg) corpus (create-corpus opts.input)] (if opts.key (print (flatten corpus (. corpus opts.key))) (print (flatten corpus opts.string))))) (main)