Introduction
CmdArgs
is a Free Pascal unit for parsing command line arguments.
Author
Frank Fischer frank-fischer@shadow-soft.de
License
Download
Latest release: cmdargs-0.4.1.tar.gz
Latext development version: cmdargs-trunk.tar.gz
Build
There are several ways to use Cmdargs
.
- Download the file
cmdargs.pas
and put it in your source directory. - Download the sources and run
fppkg install
in the root directory of the source. This will installCmdargs
as a Free Pascal package.
Usage
{$mode objfpc}
{$H+}
{$C+}
program MyProgram;
uses cmdargs;
var
args : TCmdArgs;
flag, other_flag : Boolean;
opt : String;
num : Integer;
param : String;
rest : array of String;
begin
args.add('f', 'flag', 'This is a flag'.flag(flag);
args.add('g', 'other-flag', 'This is another flag'.flag(other_flag);
args.add('o', 'opt', 'This is a string option'.arg(opt);
args.add('n', 'num', 'This is an integer').arg(num);
args.addParam('param', 'This is a positional parameter'.arg(param);
args.allowrest := true;
args.parse(['-f', '--opt', 'foo', '--num=42', 'bar', 'baz']);
rest := args.rest;
Assert(flag);
Assert(opt = 'foo');
Assert(num = 42);
Assert(param = 'bar');
Assert(Length(rest) = 1);
Assert(rest[0] = 'baz');
end.
See the API-documentation for a more detailed overview.
Documentation
The homepage of the project is at https://chiselapp.com/user/fifr/repository/pas-cmdargs.
All classes of Cmdargs
are documented in the API Documentation