options.bi | |
License | Copyright © 2007-2011, FreeBASIC Extended Library Development Group |
ext. | |
Parser | Provides an easy way to process command line arguments. |
Functions | |
addBool | Adds a boolean option to the parser. |
addOption | Adds an option to the parser. |
parse | Parses the command line and prepares the results. |
hasError | Returns true if there was an error parsing the command line. |
getError | Returns a string describing the error. |
setHelpHeader | Sets the text to show before the options list when showHelp is called. |
setHelpFooter | Sets the text to show after the options list when showHelp is called. |
showHelp | Shows the built-in help for all known options. |
isSet | Was the option passed on the command line? |
getArg | |
getRemainder | All unparsed content from the command line. |
Copyright © 2007-2011, FreeBASIC Extended Library Development Group
Contains code contributed and Copyright © 2007, mr_cha0s: ruben@gmai l.com .coder
Distributed under the FreeBASIC Extended Library Group license. See accompanying file LICENSE.txt or copy at http://code.google.com
Provides an easy way to process command line arguments. Supports short (-c) and long (--command) style arguments with optional and required parameters.
Functions | |
addBool | Adds a boolean option to the parser. |
addOption | Adds an option to the parser. |
parse | Parses the command line and prepares the results. |
hasError | Returns true if there was an error parsing the command line. |
getError | Returns a string describing the error. |
setHelpHeader | Sets the text to show before the options list when showHelp is called. |
setHelpFooter | Sets the text to show after the options list when showHelp is called. |
showHelp | Shows the built-in help for all known options. |
isSet | Was the option passed on the command line? |
getArg | |
getRemainder | All unparsed content from the command line. |
declare function addBool( byref short_opt as string, byref long_opt as string = "", byref help_string as string = "" ) as integer
Adds a boolean option to the parser.
short_opt | Single letter version of the option, e.g. c for -c |
long_opt | (optional) long form version of the option, e.g. copy for --copy |
help_string | (optional) String to print for this command when the -h or --help options are passed. |
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 = ";", byref help_string as string = "" ) as integer
Adds an option to the parser.
short_opt | Single 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 “;” |
help_string | (optional) String to print for this command when the -h or --help options are passed. |
declare sub setHelpHeader( byref s as string )
Sets the text to show before the options list when showHelp is called. When printing the help this message is displayed first, then a blank line and then the options.
declare sub setHelpFooter( byref s as string )
Sets the text to show after the options list when showHelp is called. When printing the help this message is displayed after the options preceded by a blank line.
declare sub showHelp()
Shows the built-in help for all known options. Called automatically by parse if -h or --help is passed.
declare function isSet( byval index as integer ) as bool
Was the option passed on the command line?
index | Identifier returned from addOption for an option. |
True if the option was passed on the command line.
declare function getArg( byval index as integer ) as string
index | Identifier returned from addOption for an option. |
String containing the argument passed to this option optionally seperated by the seperator if there is more than one result.
Adds a boolean option to the parser.
declare function addBool( byref short_opt as string, byref long_opt as string = "", byref help_string as string = "" ) as integer
Adds an option to the parser.
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 = ";", byref help_string as string = "" ) as integer
Parses the command line and prepares the results.
declare sub parse( byval argc as integer, byval argv as zstring ptr ptr )
Returns true if there was an error parsing the command line.
declare function hasError() as bool
Returns a string describing the error.
declare function getError() as string
Sets the text to show before the options list when showHelp is called.
declare sub setHelpHeader( byref s as string )
Shows the built-in help for all known options.
declare sub showHelp()
Sets the text to show after the options list when showHelp is called.
declare sub setHelpFooter( byref s as string )
Was the option passed on the command line?
declare function isSet( byval index as integer ) as bool
declare function getArg( byval index as integer ) as string
All unparsed content from the command line.
declare function getRemainder() as string