I'm having this problem where if I register a bunch of objects, some of them
using the use_arg function (which creates the object and returns a reference)
the previous references get broken. For instance foo.used internally changes to
true, but the reference given to let foo still says it's false. The last let
work. Whatever I put last works. I'm thinking it might be because the seq
changes size as I add new objects, messing with references, but I don't know.
I'm probably doing something very wrong, I'm open to suggestion on how to do it
better.
# Argument object
type NapArg* = object
name*: string
kind*: string
ikind*: string
required*: bool
help*: string
value*: string
used*: bool
# Array that holds all the arguments
var opts: seq[NapArg]
# Return a reference to an argument object
proc argref*(key:string): ptr NapArg =
for opt in opts.mitems:
if key == opt.name:
let adrs = addr opt
return adrs
# Same as add_arg but returns a reference to the argument object
proc use_arg*(name="", kind="", required=false, help="", value=""): ptr
NapArg =
add_arg(name, kind, required, help, value)
argref(name.strip())
add_arg(name="a", kind="flag", help="Annotate a notation")
let boo = use_arg(name="boo", kind="flag", help="Scare for life")
add_arg(name="x", kind="value", required=false, help="Cut scissors")
let foo = use_arg(name="foo", kind="value", required=true, help="Fork the
fork")
add_arg(name="path", kind="argument", required=true)
let tree = use_arg(name="tree", kind="argument", help="For the health",
value="palmera")
Run