comp • gb.args • args

Args (gb.args)

This class reimplements Args in gb.
This class is static.
This class acts like a
Returns the program argument specified by the Index parameter.
read-only
static array.
This class is
Enumerates all arguments passed to the application.
statically enumerable
with the FOR EACH keyword.

Static properties

Static methods
Return or set whether the program aborts or raises an error when an Args method fails.
Abort  
Return a copy of the process arguments as a string array.
All  
Return the number of command line arguments.
Count  
Returns Args.Count - 1
Max  
Start the program argument analysis.
Begin  
Terminate the program argument analysis, and return all arguments that could not be interpreted as an option or an option argument.
End  
Define an option that takes one string argument, and return it.
Get  
Define an option that takes one floating point number argument, and return it.
GetFloat  
Define an option that takes one integer number argument, and return it.
GetInteger  
Define an option that takes no argument, and return if it has been specified.
Has  
Get the default help message.
Must be used after Args.Begin() Returns the message text and will Print to stdout if boolean arg PrintText is True.
HelpText  

This class analyses the arguments of the current process.

It allows you to:

  • Extract options from the program arguments.

  • Automatically handle --version and --help options.

  • Return non-options as arguments.

Use the Begin method to start the option analysis and the End method to terminate it.

This class will automatically print help, usage and version messages to the standard output if -h or -V are not checked manually by the programmer.

If an error occurs, the program quits with the exit code 1.

Since 3.16.4
Set Args.Abort = False to override Quitting and handle errors yourself

Since 3.16

You can use Args.Has() to check for -V --version or -h --help manually then the default output will be suppressed and your application will not quit.

This is useful to display your own custom help or version message.

Args.HelpText() can be used to get or print the original help text if you are handling the -h manually but it MUST ONLY be called AFTER calling Args.End().

Public Sub Form_Open()
  Args.Begin(Application.Name & " <options>")
    Dim bHelp As Boolean = Args.Has("h", "help", "Display a customised help message")
  Args.End()
  If bHelp Then
    Args.HelpText(True) ' Print standard help text to terminal
     Print "Additional Help message can be written here"
    ' Now exit the program as overriding the -h argument will stop it automatically quitting.
    Stop Event
    Me.Close
    Return
  Endif
End