For most projects, we want to be able to pass some custom values when starting it.
We have ParamStr and ParamCount global functions, enough to retrieve the basic information.
On Lazarus, we got some TCustomApplication methods... one step further...
But still not enough when you want to have simple and maintainable code.
We just committed a new command line parser to our Open Source mORMot 2 framework, which works on both Delphi and FPC, follows both Windows not POSIX/Linux conventions, and has much more features (like automated generation of the help message), in an innovative and easy workflow.
The most simple code may be the following (extracted from the documentation):
var
verbose: boolean;
threads: integer;
...
with Executable.Command do
begin
ExeDescription := 'An executable to test mORMot Execute.Command';
verbose := Option(['v', 'verbose'], 'generate verbose output');
Get(['t', 'threads'], threads, '#number of threads to run', 5);
ConsoleWrite(FullDescription);
end;
This code will fill verbose and threads local variables from the command line (with some optional default value), and output on Linux:
An executable to test mORMot Execute.Command
Usage: mormot2tests [options] [params]
Options:
-v, --verbose generate verbose output
Params:
-t, --threads <number> (default 5)
number of threads to run
So, not only you can parse the command line and retrieve values, but you can also add some description text, and let generate an accurate help message when needed.
More information and source samples are available at
https://blog.synopse.info/?post/2023/04/19/New-Command-Line-Parser-in-mORMot-2 