Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

YukiRaven

Members
  • Content count

    4189
  • Joined

  • Last visited

About YukiRaven

  • Rank
    Will DDR for food

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Single Status Update

See all updates by YukiRaven

  1. I hate writing command-line parsing routines over and over in programs. Since most of my programming us done using .NET these days, I wrote a simple command-line parser library in C#. It doesn't handle a few extreme cases (no arguments, just straight files; no ability to process one argument before another when they're out-of-order on the command-line; maybe others), but it works fine otherwise. I'll probably have most of the programs I write from now on use it since it's easy to work with.

    If anyone wants to use it, it's under the GPL license and can be downloaded here: http://www.cs.du.edu/~ahunt/myprograms/libargparser/libargparser-1.0.0-src.tar.gz.

    The library can be built with build.sh (sorry Windows users, you've gotta do it manually. Which isn't hard at all). Main.cs isn't included when you run build.sh, but if you want to see how to use the library, open it up and look at the example. You could also build all the .cs files in the archive and produce an executable to see what happens.

    The basic idea is that you create an Argparser.Parser object, load it up with ArgumentDef objects, and then use the Parse() method to run everything. ArgumentDef objects have an event in them that's fired when the Execute() method is run (which is done in Parser.Parse()). It's basically like a function pointer in C++, but safer. Also, it has support for some (very) simple validation of parameters passed to arguments. In Main.cs, I included an example where the "--file" option expects two already-existing files. If it doesn't find them, it throws an exception.

    I'm 99% sure someone's thought of this before. But hey, sometimes a person is just too lazy or has too much free time to Google :)

    I didn't spend much time cleaning up the code, and no time optimizing it. It seems to run well enough to use, though, and I didn't find any bugs when testing it. Let me know if there are.

×