Use argparse instead of parseopt
This commit is contained in:
parent
27f631cc2b
commit
536bfabe32
2 changed files with 10 additions and 20 deletions
|
|
@ -13,3 +13,4 @@ bin = @["etherpad2latex"]
|
|||
|
||||
requires "nim >= 0.20.0"
|
||||
requires "jester >= 0.4.1"
|
||||
requires "argparse >= 0.7.1"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import asynchttpserver, asyncdispatch, httpclient
|
|||
import os, osproc, strutils, parseopt
|
||||
|
||||
import jester
|
||||
import argparse
|
||||
|
||||
proc getContent(pad:string, etherpadUrl:string):string =
|
||||
var client = newHTTPClient()
|
||||
|
|
@ -9,16 +10,18 @@ proc getContent(pad:string, etherpadUrl:string):string =
|
|||
|
||||
|
||||
when isMainModule:
|
||||
var
|
||||
p = initOptParser()
|
||||
port = 8080
|
||||
etherpadUrl = "http://localhost:9001/"
|
||||
var p = newParser("etherpad2latex"):
|
||||
help("Compiles etherpad pads to pdf")
|
||||
option("-p", "--port", help="Port for the server", default="8080")
|
||||
option("-a", "--etherpad-address", help="The address of the etherpad", default="http://localhost:9001")
|
||||
|
||||
let opts = p.parse()
|
||||
|
||||
router main:
|
||||
get "/@pad":
|
||||
let
|
||||
pad = @"pad"
|
||||
content = getContent(pad, etherpadUrl)
|
||||
content = getContent(pad, opts.etherpadaddress)
|
||||
texFile = open(pad & ".tex", fmWrite)
|
||||
|
||||
texFile.write(content)
|
||||
|
|
@ -30,20 +33,6 @@ when isMainModule:
|
|||
else:
|
||||
resp output
|
||||
|
||||
# Parse command-line args
|
||||
while true:
|
||||
p.next()
|
||||
case p.kind
|
||||
of cmdEnd: break
|
||||
of cmdShortOption, cmdLongOption:
|
||||
case p.key
|
||||
of "p", "port":
|
||||
port = p.val.parseInt
|
||||
of "a", "etherpad-address":
|
||||
etherpadUrl = p.val
|
||||
else: discard
|
||||
of cmdArgument: continue
|
||||
|
||||
let s = newSettings(port=Port(port))
|
||||
let s = newSettings(port=Port(opts.port.parseInt))
|
||||
var j = initJester(main, settings=s)
|
||||
j.serve()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue