initialize()

Initializes a variable defined with the Getopt type for command line argument processing.

Syntax

Getopt.initialize(
   prog_name STRING,
   argv DYNAMIC ARRAY OF STRING,
   options GetoptOptions
   )
  1. prog_name is the name of the program (typically, arg_val(0)).
  2. argv is a dynamic array of strings containing all command line arguments to be processed.
  3. options is a GetoptOptions array that holds the definition of the command line options.

Usage

This is a method for the Getopt type, used to initialize the variable of this type.

Tip: Consider using the initDefault() method instead of initialize(), if the program name must be arg_val(0) and the start index to scan command line arguments is 1.

A variable of the type Getopt must be defined, as well as a GetoptOptions dynamic array containing the definitions of the command line options for the current program.

The first parameter defines the name of the program. This is typically arg_val(0), but it can be customized.

The second argument specifies the list of command line arguments to be processed. This is typically copyArguments(1). For example, start at the second command line argument with copyArguments(2), to implement a command syntax with a verb as first argument:
$ fglrun myprog capture --verbose --filename=file1
$ fglrun myprog duplicate --source=file1 --destination=file2

The third argument contains the definition of the command options that are available with this program, defined in a GetoptOptions array.

After initializing the Getopt record, use the getopt() method to parse and validate command line options.

Example

IMPORT FGL getopt

MAIN
    DEFINE g getopt.Getopt
    DEFINE _options getopt.GetoptOptions = [ ... ]

    CALL g.inititalize("myprog", getopt.copyArguments(2), _options)
    WHILE g.getopt() == getopt.SUCCESS
        ...
    END WHILE

END MAIN