Browse documentation

Overview

Overview

Start here

Your first CLIRunnable examplesGuide index

How do I...?

Common recipesShell completionProject generator

Learn

Commands and subcommandsOptions and validationOutput, errors, and progress

Reference

Public APICurrent limitations

Inside cli-fp

Technical design

Project

Contributing and support

cli-fp: A CLI framework for Free Pascal

⚡ cli-fp: Native CLIs for Free Pascal

License: MIT Free Pascal Lazarus Supports Windows Supports Linux Version Documentation Tests

cli-fp is a small Free Pascal framework for native command-line programs. It provides command trees, validated options, generated help and shell completion, colours, spinners, and progress bars—without third-party runtime dependencies.

Your first CLI

This complete root-command program is also QuickStartDemo, compiled by the Windows and Linux example smoke checks.

program QuickStartDemo;

{$mode objfpc}{$H+}{$J-}

uses
  CLI.Interfaces, CLI.Application, CLI.Command;

type
  THelloCommand = class(TBaseCommand)
  public
    function Execute: Integer; override;
  end;

function THelloCommand.Execute: Integer;
var
  PersonName: string;
begin
  if not GetParameterValue('--name', PersonName) then
    PersonName := 'World';
  WriteLn('Hello, ', PersonName, '!');
  Result := 0;
end;

var
  App: ICLIApplication;
  Main: THelloCommand;
begin
  Main := THelloCommand.Create('', 'Print a greeting');
  Main.AddStringParameter('-n', '--name', 'Name to greet', False, 'World');
  App := CreateCLIApplication('hello', '1.0.0', Main);
  Halt(App.Execute);
end.

Compile from a clone of this repository:

fpc -Fu./src ./examples/QuickStartDemo/QuickStartDemo.lpr
./examples/QuickStartDemo/QuickStartDemo --name Ada
$ ./examples/QuickStartDemo/QuickStartDemo --name Ada
Hello, Ada!

On PowerShell, use fpc "-Fu.\src" .\examples\QuickStartDemo\QuickStartDemo.lpr and run .\examples\QuickStartDemo\QuickStartDemo.exe --name Ada.

Choose a CLI shape

ShapeInvocationStart with
One default actionhello --name AdaRoot command
Named commandstool greet --name AdaNamed command
Nested commandstool repo clone --url …Subcommand

Documentation

Examples and generator

The runnable examples progress from QuickStartDemo through root, named, nested, error-handling, colour, and progress applications. They are compiled by the cross-platform cleanup smoke checks.

Use cli-fp-gen when a larger command tree benefits from a scaffolded project layout. It is optional; the program above is the shortest way to start.

Requirements

Contributing

See the contribution guide. On Windows, run:

powershell -ExecutionPolicy Bypass -File tests\run_tests.ps1
powershell -ExecutionPolicy Bypass -File tests\codegen\run_all_tests.ps1
powershell -ExecutionPolicy Bypass -File tests\run_cleanup_smoke.ps1

The Bash equivalents and the full project map are in the contribution guide.

License

cli-fp is available under the MIT License.