Download
(5Kb)
Download
Updated: 10-15-08 12:47 AM
Updated:10-15-08 12:47 AM
Created:unknown
Downloads:3,353
Favorites:6
MD5:

GetOpt

Version: 0.03
by: seebs [More]

Very simply, this is a clone of the classic UNIX getopt() function, loved by developers everywhere because parsing options is annoying.

Hand this a command line, and watch it magically extract flags from it. Uses UNIX conventions -- "-a" or "--absolute", not "/a" or just a keyword. Small and fairly lightly tested, but it does what I want.

Not following what I just said? Imagine that you want a slash command to accept a number of arguments. You hand your command line to getopt:

args = GetOpt.getopt("ab:", "-a -b Barney hello there")

Now, args["a"] = true, args["b"] = Barney, and args["leftover"] = "hello there". You can pass the arguments in as a string or as a table; if a string, it is parsed automatically, including trying to handle simple command-line quoting.

Basically, this does all the annoying stuff you usually have to do to parse a command line.

Just TOC updates.
Optional Files (0)


Post A Reply Comment Options
Unread 05-02-09, 03:02 AM  
seebs
Premium Member
Premium Member
AddOn Author - Click to view AddOns

Forum posts: 155
File comments: 157
Uploads: 5
Re: kudos and feature request (boolean-type)

Originally posted by Macniel
Good job on this Library, it works like a charm; but when you Parse -? (--help , too?) and you haven't set up a -? parameter yet you encounter a "-? is an unkown parameter" but you get, as expected, the parameter list.

I would, if I may, request more parameter types such as boolean that would be very cool
I'm not quite sure I get the boolean thing -- plain old options are booleans by default. If "-a" doesn't take an argument, then it's a boolean which is set if you provide it and not set otherwise. Effectively.
Report comment to moderator  
Reply With Quote
Unread 04-13-09, 05:31 PM  
Macniel
A Fallenroot Satyr
 
Macniel's Avatar
AddOn Author - Click to view AddOns

Forum posts: 26
File comments: 113
Uploads: 8
Thumbs up kudos and feature request (boolean-type)

Good job on this Library, it works like a charm; but when you Parse -? (--help , too?) and you haven't set up a -? parameter yet you encounter a "-? is an unkown parameter" but you get, as expected, the parameter list.

I would, if I may, request more parameter types such as boolean that would be very cool
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: