Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nim: CLI opts parsing #135

Open
konsumer opened this issue Feb 17, 2023 · 0 comments
Open

nim: CLI opts parsing #135

konsumer opened this issue Feb 17, 2023 · 0 comments
Labels
enhancement New feature or request nim Nim-specific

Comments

@konsumer
Copy link

konsumer commented Feb 17, 2023

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.)

@shish shish added enhancement New feature or request nim Nim-specific labels Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nim Nim-specific
Projects
None yet
Development

No branches or pull requests

2 participants