OptionParser.Option

Enums

OptionType

Represent a valid type of option.

  • String
  • Integer - Supplied value must be a valid number
  • Double - Supplied value must be a valid number
  • Date - Supplied value must pass ParseDate()
  • Boolean - If supplied value is "", "y", "yes", "t", "true", "on", "1" then it is considered True, otherwise False
  • File - Represented by a FolderItem
  • Directory - Represented by a FolderItem

Properties

Description As String

Description that will appear in the application help for this option.

IsArray As Boolean

For example, say this option has IsArray=True and is -i/--include. On the command line one could:

$ myapp -i include -i project/include -i support/include abc.c

In code would look like:

Dim v() As Variant = optParser.ArrayValue("include")

Print v(0) // include
Print v(1) // project/include
Print v(2) // support/include

If True, this option will handle multiple values and store those values into an array, even if one or none.

IsReadableRequired As Boolean

When set to True validation will be done on a OptionType.File and OptionType.Folder to ensure that it can be read from. If the validation fails a OptionInvalidKeyValueException exception will be raised.

NOTE: This does not mean that the option is required. It simply means that if supplied, the option needs to be readable. If you want to make sure that the option is both readable and required, one should also set IsRequired=True.

IsRequired As Boolean

If set to True, this option will be required to be supplied at the command line. If it is not supplied, a OptionMissingKeyException will be raised.

IsValid As Boolean

Read-only property that one can check to ensure if the Option value is valid or not.

IsValidDateRequired As Boolean

When set to True validation is performed on the supplied value to make sure it is a valid date. If the validation fails a OptionInvalidKeyValueException exception will be raised.

NOTE: This does not mean that the option is required. It simply means that if supplied, the option needs to be a valid date. If you want to make sure that the option is both a readable date and required, one should also set IsRequired=True.

IsWriteableRequired As Boolean

When set to True validation will be done on a OptionType.File and OptionType.Folder to ensure that it can be written to. If the validation fails a OptionInvalidKeyValueException exception will be raised.

NOTE: This does not mean that the option is required. It simply means that if supplied, the option needs to be writeable. If you want to make sure that the option is both writeable and required, one should also set IsRequired=True.

LongKey As String

An option can have a short and long key. This is the long key. A key is what the user supplies on the command line to supply a particular value to a given option.

For example, suppose you are writing a Hello World program and wish to accept a name on the command line of who to say hello to. The long option name be "name" while the short "n".

$ say-hello -n John
Hello John!
$ say-hello --name=John
Hello John!

MaximumNumber As Double = kNumberNotSet

Set a maximum limit to an Integer or Double option type.

NOTE: This does not mean that the option is required. It simply means that if supplied, the option needs to be no more than this. If you want to make sure that the option has a maximum value and is required, one should also set IsRequired=True.

MinimumNumber As Double = kNumberNotSet

Set a minimum limit to an Integer or Double option type.

NOTE: This does not mean that the option is required. It simply means that if supplied, the option needs to be no less than this. If you want to make sure that the option has a minimum value and is required, one should also set IsRequired=True.

ShortKey As String

An option can have a short and long key. This is the short key. A key is what the user supplies on the command line to supply a particular value to a given option.

For example, suppose you are writing a Hello World program and wish to accept a name on the command line of who to say hello to. The long option name be "name" while the short "n".

$ say-hello -n John
Hello John!
$ say-hello --name=John
Hello John!

Type As OptionType

Get or Set what type of option this is.

Please see the OptionType enum for more information.

TypeString As String

Retrieve a String representation of the enum OptionType associated with this option.

Value As Variant

Get or set the user supplied value of this option.

WasSet As Boolean

If the option was supplied on the command line, WasSet will return True. Otherwise it will return False. This can be used to determine if a default value should be used or maybe further user prompting.

Methods

Constructor(shortKey As String, longKey As String, description As String, type As OptionType = OptionType.String)

Construct a new Option for use with OptionParser. Provides most common attributes about an option as parameters.

Parameters

  • shortKey - Option's short key, can be blank
  • longKey - Option's long key, can be blank
  • description - Description of option used when display the help message
  • type - Type of this option, see OptionType enum

Notes

While both shortKey and longKey are optional, one must be supplied. Further, longKey must be more than 1 character in length.

Example

Dim opt As New OptionParser

Dim o As Option
o = New Option("", "name", "Name to say hello to")
o.IsRequired = True
opt.AddOption o

opt.AddOption New Option("", "count", "Number of times to say hello", Option.OptionType.Integer)

Validate and cleanup

HandleValue(value As String)

For internal OptionParser use.

Handles converting the String representation of an option as supplied by the user to the actual OptionType, for example, converts a String to an Integer, Double, Date, Boolean, FolderItem, etc...