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

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

Open
tavurth opened this issue May 12, 2022 · 3 comments
Open

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

tavurth opened this issue May 12, 2022 · 3 comments

Comments

@tavurth
Copy link

tavurth commented May 12, 2022

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
Copy link
Author

tavurth commented May 12, 2022

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
Copy link
Owner

iffy commented May 12, 2022

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
Copy link
Owner

iffy commented May 12, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants