Overview
simple_cli provides a clean, fluent API for parsing command-line arguments in Eiffel applications. It handles flags, options with values, positional arguments, subcommands, and automatic help generation.
Part of the Simple Eiffel ecosystem.
Quick Start
Installation
- Set the environment variable:
export SIMPLE_EIFFEL=/d/prod - Add to your ECF file:
<library name="simple_cli" location="$SIMPLE_EIFFEL/simple_cli/simple_cli.ecf"/>
Basic Usage
local
cli: SIMPLE_CLI
do
create cli.make
cli.set_app_info ("myapp", "My Application", "1.0.0")
-- Define options
cli.add_flag ("v|verbose", "Enable verbose output")
cli.add_option ("o|output", "Output file", "FILE")
-- Parse and use
cli.parse
if cli.help_requested then
cli.print_help
elseif cli.has_errors then
cli.print_errors
else
if cli.has_flag ("verbose") then
print ("Verbose mode%N")
end
end
end
Key Features
Fluent API
Chain configuration calls for clean, readable option definitions.
Flags & Options
Boolean flags, string options, defaults, and required options.
Short & Long Names
Define both formats: "v|verbose" gives -v and --verbose.
Auto Help
Generates formatted help text from option definitions.
Typed Access
Get values as strings, integers, or booleans with defaults.
Subcommands
Git-style commands with arguments_after_command.
Examples
Subcommand Pattern
local
cli: SIMPLE_CLI
do
create cli.make
cli.set_app_info ("pkg", "Package Manager", "1.0.0")
cli.add_flag ("v|verbose", "Verbose output")
cli.parse
if attached cli.command as cmd then
inspect cmd
when "install" then
-- pkg install package1 package2
across cli.arguments_after_command as pkg loop
install_package (pkg)
end
when "remove" then
handle_remove (cli)
else
print ("Unknown command%N")
end
end
end
Required Options
cli.add_required_option ("i|input", "Input file", "FILE")
cli.add_required_option ("o|output", "Output file", "FILE")
cli.add_option_with_default ("f|format", "Format", "FMT", "json")
cli.parse
if cli.has_errors then
-- "Required option missing: --input"
cli.print_errors
end
Documentation
- User Guide - Complete tutorial with examples
- API Reference - Full feature documentation
- Architecture - Internal design and rationale
- Cookbook - Real-world recipes and patterns