PHP Classes
elePHPant
Icontem

PHP Get Console Arguments: Read and parse arguments for command line scripts

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2014-11-14 (3 years ago) RSS 2.0 feedNot enough user ratingsTotal: 222 All time: 7,840 This week: 943Up
Version License PHP version Categories
console-args 1.0.2MIT/X Consortium ...5.3PHP 5, Console
Description Author

This class can read and parse arguments for command line scripts.

It takes an array with the command line arguments passed from the console and parses them according to the definition of expected arguments passed as another array.

The class supports boolean options that are enabled by the presence of argument like --help, and string options that have associated values like --file=filename. other values that do not start with -- are ignored.

The class returns argument values using getter functions.

  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 49
All time rank: 104820 in Spain Spain
Week rank: 241 Up8 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Details

Latest Stable Version Total Downloads Latest Unstable Version License

console-args

This is an wrapper for the argv global

The difference between arguments and options are: * arguments are strings like `--help` * options are strings like `--file=filename` * other arguments without `--` are not recognized because the magic of this wrapper is that doesn't matter the order of the arguments/options

Version

1.0.0

Installation

Add the module by composer.json, adding in require clause:

{
    "jlaso/console-args": "1.0.0"
}

Sample of use

$consoleArgs = new ConsoleArgs($argv, array('help'), array('arg1', 'arg2'));

if($consoleArgs->hasHelp){
    print <<<EOD
        Please, use this arguments to invoke this command:

             --help       \tto see this help
             --arg1=filename \tthe first argument
             --arg2=filename\toptional, the second argument
EOD;
   exit();
}
$arg1 = $consoleArgs->getArg1;
$arg2 = $consoleArgs->getArg2;

License

MIT

  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file ConsoleArgs.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file VERSION Data Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:222
This week:0
All time:7,840
This week:943Up
User Comments (1)
For command line lovers like me, thats a great class :-D
2 years ago (Josť Filipe Lopes Santos)
70%StarStarStarStar