iffy / nim-argparse

Argument parsing for Nim
MIT License
120 stars 8 forks source link

Which type to use when passing `optsIdent` to a function? #79

Open tavurth opened 2 years ago

tavurth commented 2 years ago

Hi I was wondering which type I should use to pass the arguments around, something like this:

proc some_run_func(opts: WhatShouldThisTypeBe?): void =
  echo opts

var parser = newParser("server"):
  flag("-p", "--preload", help="Should we preload data")

try:
  some_run_func(parser.parse())
except UsageError:
  echo parser.help
  stderr.writeLine getCurrentExceptionMsg()
  quit(1)
tavurth commented 2 years ago

Seems that changing my code to template works, but it would be really nice to have a way to convert the current argument set to a tuple.

template some_run_func(opts: untyped): void =
  echo opts.preload

var parser = newParser("server"):
  flag("-p", "--preload", help="Should we preload data")

try:
  some_run_func(parser.parse())
except UsageError:
  echo parser.help
  stderr.writeLine getCurrentExceptionMsg()
  quit(1)
iffy commented 2 years ago

This is related to #63

Unfortunately, there's not a type defined that you can use at this point. But I realize how valuable it would be. I'll see if anything has changed in the latest versions of Nim.

iffy commented 2 years ago

Looks like the situation is the same. When I get around to #78, I may attempt a refactor that would expose the options type to users.