nim: CLI opts parsing
Opened this issue · 0 comments
konsumer commented
You mention in README
Unless I'm missing something, command line parsing is really bad.
You should check out docopt! It's not the only way to do it in nim, but it's pretty nice. It parses your help-text and makes it pretty easy.
Here is an example from a recent project:
import docopt
const doc = """
null0 - Runtime for null0 game-engine
Usage:
null0 <cart>
null0 --help
null0 --net <cart>
<cart> Specify the cart-name (wasm file or zip/directory with main.wasm in it)
Options:
-h --help Show this screen.
-n,--net Allow cart to access networking
"""
proc main() =
let args = docopt(doc, version = "0.0.1")
if args["--net"]:
# do net stuff
cartLoad($args["<cart>"])
It adds all the options and understands -n,--net
are aliases, and other little things. It knows it should demand a <cart>
and shows a simplified help, if you don't provide it. It seems pretty tolerant of different formats (like I added documentation for <cart>
in a few places, and it kept working, fine.)