options.bi

Summary
options.bi
LicenseCopyright © 2009, FreeBASIC Extended Library Development Group
ext. options
ParserProvides an easy way to process command line arguments.
Functions
addOptionAdds an option to the parser.
parseParses the command line and prepares the results.
hasErrorReturns true if there was an error parsing the command line.
getErrorReturns a string describing the error.
isSetWas the option passed on the command line?
getArg
getRemainderAll unparsed content from the command line.

License

Copyright © 2009, FreeBASIC Extended Library Development Group

Contains code contributed and Copyright © 2007, mr_cha0s: ruben.nosp@m..coder@gmai.nosp@m.l.com

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com- /p- /fb-extended-lib- /wiki- /License

ext. options

Parser

Provides an easy way to process command line arguments.  Supports short (-c) and long (--command) style arguments with optional and required parameters.

Summary
Functions
addOptionAdds an option to the parser.
parseParses the command line and prepares the results.
hasErrorReturns true if there was an error parsing the command line.
getErrorReturns a string describing the error.
isSetWas the option passed on the command line?
getArg
getRemainderAll unparsed content from the command line.

Functions

addOption

declare function addOption(byref short_opt as string,  
byref long_opt as string =  "",
byval has_arg as bool =  false,
byval arg_required as bool =  false,
byval can_repeat as bool =  false,
byref rep_seperator as string =  ";") as integer

Adds an option to the parser.

Parameters

short_optSingle letter version of the option, e.g. c for -c
long_opt(optional) long form version of the option, e.g. copy for --copy
has_arg(optional) option has argument, defaults to false, e.g.  --copy filename where filename is the argument
arg_required(optional) is the argument required, defaults to false
can_repeat(optional) can the argument repeat, defaults to false, e.g.  --copy file1 --copy file2
rep_seperator(optional) if the argument can repeat what should the results be seperated by, defaults to “;”

Returns

Integer identifier for this option used in isSet and getArg

parse

declare sub parse(byval argc as integer,
byval argv as zstring ptr ptr)

Parses the command line and prepares the results.

Usage

myOptions.parse( __FB_ARGC__, __FB_ARGV__ )

hasError

declare function hasError() as bool

Returns true if there was an error parsing the command line.

getError

declare function getError() as string

Returns a string describing the error.

isSet

declare function isSet(byval index as integer) as bool

Was the option passed on the command line?

Parameters

indexIdentifier returned from addOption for an option.

Returns

True if the option was passed on the command line.

getArg

declare function getArg(byval index as integer) as string

Parameters

indexIdentifier returned from addOption for an option.

Returns

String containing the argument passed to this option optionally seperated by the seperator if there is more than one result.

getRemainder

declare function getRemainder() as string

Returns

All unparsed content from the command line.

declare function addOption(byref short_opt as string,  
byref long_opt as string =  "",
byval has_arg as bool =  false,
byval arg_required as bool =  false,
byval can_repeat as bool =  false,
byref rep_seperator as string =  ";") as integer
Adds an option to the parser.
declare sub parse(byval argc as integer,
byval argv as zstring ptr ptr)
Parses the command line and prepares the results.
declare function hasError() as bool
Returns true if there was an error parsing the command line.
declare function getError() as string
Returns a string describing the error.
declare function isSet(byval index as integer) as bool
Was the option passed on the command line?
declare function getArg(byval index as integer) as string
declare function getRemainder() as string
All unparsed content from the command line.