Jump to content




[UPDATED!] GetOpts, a linux-styled argument parser


10 replies to this topic

#1 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 November 2016 - 03:11 PM

GetOpts, a linux-styled argument parser
*Updated. The old version is depreciated, and will soon be removed.

MORE PLANNED UPDATES:
  • Add substitution of a table of arg sets for the number of args.
  • Test function for itable reversion
  • Add more itable management functions
NOTE: Make sure to pass the true as an argument to getOpts.newStruct, otherwise help and escaping will not be generated!

pastebin get PSFnwfPp getOpts

Example Program

APIS:
[object parserObject]
  :add(aliases, fullname, help, runFunc, maxArgs or nil, usage) --runFunc is a function with args [args [, [object parserObject]]]
  :addM([same args as :add]) --Same as add, but creates mandatory args
  :setHeader(head) --Creates the help header
  .opts --a table with more tables, stores flag info
  .functions --Only available in flags
	.escape(escapepoint) --Escaping. If a number is provided, anything >= that number will be escaped. If a table is provided, those specific arguments are escaped.
	.toITable() --Removes gaps from tables
	.getFlagPos() --Untested, returns pos of current flag
	
  
loadfile('getOpts', _G)()
  .getArgs(string) returns table  --A tokeniser
  .toITable(table) --removes gaps from table
  .help(struct.opts, struct.header) --Prints help screen
  .parse(struct, args) returns table --Returns left over args, this is the main function
  .newStruct(autoGenItems) returns [object parserObject]

What has changed?
  • Items can now be called multiple times
  • New functions
  • Reversed args for the function used for :add func argument, now args, parser instead of parser, args
  • Now run in chronological order
  • You can figure out which numbered item from the original table args were. The indices on the argument tables contain gaps.
  • Added anon functions. The -% flag is now an anon function and is no longer hard-coded in
  • added usage arg to :add
WARNING:
Initializing a struct without the autoGenItems flag will not contain help and -%. Re-initializing the parser.opts table will also remove these.



Old post

Edited by EveryOS, 19 December 2017 - 03:05 PM.


#2 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 30 November 2016 - 04:20 PM

dammit i was gonna make one today :^) Looks like someone beat me to it. Also i swear soneone already made one of these?

#3 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 November 2016 - 08:31 PM

ironic. well it is very buggy i made it on a mobile device and debuged it later

#4 Admicos

  • Members
  • 207 posts
  • LocationTurkey

Posted 30 November 2016 - 09:14 PM

 TheRockettek, on 30 November 2016 - 04:20 PM, said:

dammit i was gonna make one today :^) Looks like someone beat me to it. Also i swear soneone already made one of these?

Was it me?

Joking aside, i feel like your output looks a little "messy". But i haven't tried the rest of it myself. Other than that, it looks ok.

#5 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 30 November 2016 - 11:05 PM

Oh, I didn't realize you already made something like this, with, ironically, the exact same name.

Well anyways, here's were I'm planning on going from here

--I'll completely redo the parse function. It doesn't work very well with tables containing multiple items.

--Ill add checkForArg(t, arg or aliases)
--Ill add newStruct():nonm(arg or aliases)
--Ill add newStruct():m(arg or aliases)
Ill edit newStruct() to take argument autoCreateBasicFramework, a boolean value

Also, there is a feature I didn't tell you about, mainly because it doesn't work correctly.

#6 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 20 July 2017 - 08:09 PM

Im going to be redoing this soon. In the meantime, may you remove this topic?

#7 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 20 July 2017 - 10:52 PM

 EveryOS, on 20 July 2017 - 08:09 PM, said:

Im going to be redoing this soon. In the meantime, may you remove this topic?

You could just edit the main post, and keep it up and once it's done comment at the bottom with an update?

#8 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 21 July 2017 - 05:29 PM

OK

#9 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 26 September 2017 - 04:24 PM

Updated post! I'll re-add image soon.

#10 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 13 December 2017 - 05:44 PM

GetOpts has been updated (again!). The post has been updated.

Edited by EveryOS, 13 December 2017 - 05:45 PM.


#11 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 19 December 2017 - 03:05 PM

EVEN MORE UPDATES!

Turns out I already implemented function-less flags. I made -% function-less and fixed broken escape function





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users