Download
(11 Kb)
Download
Updated: 07-12-13 07:57 PM
Updated:07-12-13 07:57 PM
Created:10-12-11 07:04 PM
Downloads:149
Favorites:1
MD5:
LibGetOpt
Version: 0.13
by: seebs [More]
LibGetOpt is a preliminary draft of an addon to do, well, exactly what the name suggests: Parse options in a format that will be familiar to Unix users everywhere.

Example usage:

Library.LibGetOpt("a:b", "-a foo -b bar baz")

This would yield a table

{
"a" => "foo"
"b" => true
"leftover" => "bar baz"
"leftover_args" => { "bar" "baz" }
}

It can also register a slash command for you such that your function gets called with such a table instead of a string.

The intent is that this will allow addon developers to add simple flag options to their slash commands without having to reinvent that particular wheel.

The only thing you can do with this without adding it to another addon is "/getopt -d 2" to set debugging on... You can also pass other words to it to see how the quoting works.

I finally fixed the quoting so it handles backslashes and quotes in the middle of words and everything else correctly. Want that? Library.LibGetOpt.dequote(string) yields a table of the words in string, respecting quoting conventions.
0.9:
* Various fixes
* Support for multiply-specified options
0.10:
* TOC update.

0.11:
* ToC update
* change way printf is used

0.12:
* Make leftover_full available for the full text (including quotes and backslashes) of any unused material.

0.13:
* New event model (affects Command.Slash.Register)
Optional Files (0)


Archived Files (6)
File Name
Version
Size
Author
Date
0.12
11kB
seebs
02-24-13 09:01 PM
0.11
10kB
seebs
11-03-12 01:43 AM
0.10
7kB
seebs
06-22-12 09:48 PM
0.9
7kB
seebs
03-16-12 01:06 PM
0.5
5kB
seebs
10-12-11 10:23 PM
0.4
4kB
seebs
10-12-11 07:04 PM


Post A Reply Comment Options
Old 07-13-13, 04:26 AM  
Mere
Zombie
AddOn Author - Click to view AddOns

Forum posts: 4
File comments: 84
Uploads: 0
Thanks for the update (one less library to worry about failing when the event api changes over)

Note that /getopt -d no longer works, as you forgot to add the extra param to:
function GetOpt.slashcommand(args)

Thanks,
Mere
Mere is offline Report comment to moderator  
Reply With Quote
Old 07-08-13, 11:10 AM  
seebs
Super Moderator
Riftui Super Moderator
AddOn Author - Click to view AddOns

Forum posts: 9
File comments: 31
Uploads: 35
Hey, thanks for the birthday wishes. Yes, there's at least one global leak in LibGetOpt, which I think I've fixed in my local tree, and also yes a new version is needed for the new event stuff. It's done locally, haven't uploaded. I should do that Real Soon.
seebs is offline Report comment to moderator  
Reply With Quote
Old 06-26-13, 01:18 PM  
Mere
Zombie
AddOn Author - Click to view AddOns

Forum posts: 4
File comments: 84
Uploads: 0
Hi Seebs,

I was wondering if you've an update planned to support the new event hooking for the command registration?

If you are, there's also a couple of possible global leaks, in getopt, the:
arg = args[i]
and in slashCommand:
x = GetOpt.getopt("d#", args)

both look like they could be locals?

Thanks,
Mere

(PS happy birthday)
Mere is offline Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: