Quick start

Create a project

Create a project named helloWorld using Lazarus or an editor of your preference.

Manual install

Boss install

Another option to install pascli is using the boss (check it for installation instructions). If boss is already installed: just type in the command line from the project folder:

boss init --quiet
boss install github.com/leandro-lprsoft/pascli

This commands will download the library inside a subfolder "modules/pascli/src" and add this new path to the search path of the project.

Why use boss? It manages project dependencies and allows you to update dependencies when needed. It allows you to quickly operate with a previous version of that dependency reducing compatibility risks with new versions. When a new version appears you can simply type from the command line in the project folder:

boss update

Edit the project

Open the project using Lazarus or an editor of your preference and replace all with the following code:

program helloWorld;

{$MODE DELPHI}{$H+}

uses
  {$IFDEF UNIX}
  cmem, cthreads,
  {$ENDIF}
  Command.Interfaces,
  Command.App,
  Command.Usage,
  Command.Version;

var
  Application: TCommandApp;

{$R *.res}

procedure HelloCommand(ABuilder: ICommandBuilder);
begin
  WriteLn('Hello world!');
end;

begin
  Application := TCommandApp.Create(nil);
  Application.Title := 'a basic cli tool sample project';

  Command.Usage.Registry(Application.CommandBuilder);
  Command.Version.Registry(Application.CommandBuilder);

  Application
    .CommandBuilder
      .AddCommand(
        'hello',
        'Show a hello world message.''Show a hello world message.'#13#10 +
        'Ex: basic hello',
        @HelloCommand,
        [ccNoParameters]);

  Application.Run;
  Application.Free;
end.

Now compile it, open a terminal at the project source path and type the following:

./helloWorld

You should see the following output:

helloWorld version 1.0.0

Usage: helloWorld [command] 

a basic cli tool sample project

Commands: 
  help           Shows information about how to use this tool or about a specific command.
                 Ex: helloWorld help
  version        Shows the helloWorld version information
                 Ex: helloWorld version
  hello          Show a hello world message.'Show a hello world message.
                 Ex: basic hello

Run 'helloWorld help COMMAND

Try the following command to see the output:

./helloWorld help hello

This command shows how to use the "hello" command, if there were available options, they would be displayed. Now you may explore this small program, try to change HelloCommand procedure to output different text. Try the tutorial to see the use of advanced options or just explore the library reference to check what is available.

Next Application structure


Generated by PasDoc 0.16.0.