Skip to content

webtrendi/clapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLAPP: Command Line Argument Parser For PHP

Build Status

Parses command line arguments passed to a PHP script.

Usage

// Define accepted arguments
$definitions = new \Clapp\CommandLineArgumentDefinition(array(
    "help|h"      => "Shows help message",
    "message|m=s" => "Input message",
    "verbose|v+"  => "Set level of verbose output",
));

// Filter arguments based and validate according to definitions
$filter = new \Clapp\CommandArgumentFilter($definitions, $argv);

// Retrieve parameter if set
if ($filter->getParam('h') !== false) {
    echo $definitions->getUsage();
    exit();
} //if

Features

  • Simple definition syntax
  • Supports long and short arugment names (-v --verbose)
  • Supports repeated arguments (--name=bob --name=mary)
  • Supports multiple short arguments (-abc equivalent of -a -b -c)
  • Supports 2 ways of setting values (--name=bob or --name bob)
  • Supports double dash delimiter for trailing values
  • Creates detailed usage documentation using definitions