Skip to content

Examples

Greg Bowler edited this page Mar 3, 2026 · 2 revisions

The example/ directory contains runnable scripts that progress from simple output to full multi-command applications.

To run any example from the project root:

php example/01-hello-world.php

Example index

  1. 01-hello-world.php Outputs a single message using command output helpers.

  2. 02-greeter.php Accepts an optional named argument and prints a personalised greeting.

  3. 03-colour.php Demonstrates one-off coloured output and persistent output palettes.

  4. 04-parameters-and-flags.php Shows required named arguments, optional named arguments, required options and optional flags together.

  5. 05-interactive.php Demonstrates interactive input with readLine() when optional arguments are omitted.

  6. 06-multi-command.php Creates a multi-command CLI with sum, repeat, and built-in help.

  7. 07-repeating-lines.php Demonstrates suppression markers for repeated consecutive output lines.

  8. 08-progress-bar.php Shows an in-place progress bar that updates on one terminal line.

The examples are intentionally small and anonymous-class based so they can be copied directly into new scripts while keeping setup noise low.


Next, read parameters and arguments for how command contracts are defined.

Clone this wiki locally