On Friday, 28 March 2014 at 15:39:48 UTC, monarch_dodra wrote:
On Friday, 28 March 2014 at 14:42:54 UTC, Colin Grogan wrote:
Im trying to parse command line args and then build a struct
that will, at run-time, hold the data the user passed in via
command line args.
Very similar to Pythons docopt utility ->
https://github.com/docopt/docopt
Up till now, I've been using templates to do all of the work,
but now that I realise I can do it all with functions I might
try that. Then use a mixin template to create the struct with
whatever data is required.
Thanks.
I'm sure I'll be back to bombard ye with questions soon!
Did you try looking into "std.getopt"? It's pretty much the
same thing. It doesn't quite do the "useage/help" thing
automatically though (yet). But, IMO, that's trivial to
implement.
It's the parsing of arguments you don't want to rewrite. That's
complicated.
I did, and use it a good bit.
I'm kind of doing this as an exercise in learning, though I do
think the using docopt is a bit easier than using std.getopt, so
it may be of use once its done too.
The trouble I find with getopt is that you have to write a
section at the start of your main function every time, and then
you need to write help text aswell. This is all in one, and
hopefully will be called with one function.
What I'm working towards is:
auto parsed = docopt!helpText(args);
Anyway, this is a bit off topic :)