Class TParameters
Unit
Declaration
type TParameters = class(TCastleStringList)
Description
Storing and processing command-line parameters and options. For simple processing, you can just read values of this list, checking count with comfortable methods like CheckHigh. For more involved processing, use the Parse function, that does a whole job for you based on a simple specification of allowed options.
Some terminology:
- Parameter
Command-line parameters list is given directly by the OS to our program. These are the contents of this list, initialized from the standard Pascal ParamStr/ParamCount. They can be modified to remove the already-handled parameters.
- Option
Options are things encoded by the user in the parameters. Examples:
Command-line
castle-model-viewer --navigation Walk
passes two parameters (
--navigationandWalk) for castle-model-viewer, and these two parameters form one option:--navigation=Walk.Command-line
castle-model-viewer -hv
passes one parameter (
-hv) for castle-model-viewer, and inside this parameter two options are encoded:-hand-v.
The very idea of this unit is to decode "options" from the "parameters".
- Argument
Argument is a part of the option, that clarifies what this option does. For example in
--navigation=Walk, "Walk" is the argument and "--navigation" is the option long name.Some options don't take any arguments, some take optional argument, some take required argument, some have a couple of arguments. TOptionArgument type allows you to specify all this.
For simple programs, you can directly parse command-line by looking at our parameters strings. For more involved cases, using Parse method has a lot of advantages:
Less error-prone, and your program's code stays simple.
We automatically handle special parameter -- that is a standard way to mark the end of the options. (Useful for users that have filenames that start with "-" character.)
We automatically detect and make exceptions with nice messages on various errors. For example unrecognized options are clearly reported (so they will not mistaken for e.g. missing filenames by your program).
We automatically allow combining of short options, so user can use
-abcinstead of-a -b -c.We have a simple interface, where you simply specify what options you want, long and short option names, option arguments and such.
See [https://castle-engine.io/common_options.php] for a user description how short and long options are expected to be given on the command-line.
Source: base/castleparameters.pas (line 229).
Hierarchy
- TObject
- TPersistent
- TStrings
- TStringList
- TCastleStringList
- TParameters
Generated by PasDoc 0.17.0.snapshot.