CmdArgs  CmdArgs

Introduction

CmdArgs is a Free Pascal unit for parsing command line arguments.

Author

Frank Fischer frank-fischer@shadow-soft.de

License

GPL 3.0

Download

Latest release: cmdargs-0.1.0.tar.gz

Latext development version: cmdargs-trunk.tar.gz

Build

There are several ways to use Cmdargs.

  1. Download the file cmdargs.pas and put it in your source directory.
  2. Download the sources and run fppkg install in the root directory of the source. This will install Cmdargs 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.flag('f', 'flag', 'This is a flag', flag);
   args.flag('g', 'other-flag', 'This is another flag', other_flag);
   args.opt('o', 'opt', 'This is a string option', opt);
   args.opt('n', 'num', 'This is an integer', num);
   args.param('param', 'This is a positional parameter', 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