Skip to content

Commit

Permalink
GH-Issue #10 : Added "help" to command line (and additionally removed…
Browse files Browse the repository at this point in the history
… the need for silly things like "true" onb --quiet
  • Loading branch information
enygma committed Oct 27, 2010
1 parent 53322ab commit b02fa1e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
9 changes: 8 additions & 1 deletion frisk
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ set_include_path(get_include_path().
PATH_SEPARATOR.__DIR__.'/lib/Exceptions'.
PATH_SEPARATOR.__DIR__.'/tests');

HelperArguments::execute($_SERVER['argv']);

// See if they just need help
if(HelperArguments::getArgument('help')){
HelperArguments::displayArgumentHelp();
die();
}

$runner = new Runner();
try{
HelperArguments::execute($_SERVER['argv']);
HelperConfig::execute(null);

ob_start();
Expand Down
49 changes: 45 additions & 4 deletions lib/Helper/HelperArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
class HelperArguments extends Helper
{

/**
* Details for current arguments (spit out on call to --help)
* @var array
*/
static $argumentDetails = array(
'quiet' => array('','Suppresses all output, nothing returned'),
'output' => array('[type]','Controls output format (ex. XML, JSON, CSV, etc)'),
'config' => array('[file path]','Path to the configuration file to use'),
'test' => array('[test name]','Run a single test with this name'),
'verbose' => array('','Add more verbose reporting to testing output'),
'help' => array('','Display this message')
);

/**
* Arguments currently defined on execution
* @var array
*/
static $currentArguments = array();

/**
Expand All @@ -20,10 +37,9 @@ public function execute($arguments)
if(!empty($arguments)){
foreach($arguments as $argument){
$argumentParts = explode('=',$argument);
if(count($argumentParts)>1){
$argumentKey = str_replace('--','',$argumentParts[0]);
self::$currentArguments[$argumentKey]=$argumentParts[1];
}
$argumentKey = str_replace('--','',$argumentParts[0]);

self::$currentArguments[$argumentKey] = (count($argumentParts)>1) ? $argumentParts[1] : true;
}
}
}
Expand Down Expand Up @@ -70,6 +86,31 @@ public static function getArgument($name)
return (isset(self::$currentArguments[$name])) ? self::$currentArguments[$name] : null;
}

/**
* Display the contents of the argument detail from above
*
* @return void
*/
public static function displayArgumentHelp()
{
echo "Frisk command-line parameters:\n";
echo "=======================================\n";

// find the longest argument info
$longestParameter = 0;
foreach(self::$argumentDetails as $argumentName => $argumentDetail){
$argumentString='--'.$argumentName.((!empty($argumentDetail[0])) ? ' = '.$argumentDetail[0] : '');
if(strlen($argumentString)>$longestParameter){ $longestParameter=strlen($argumentString); }
}

foreach(self::$argumentDetails as $argumentName => $argumentDetail){
$argumentString="--".$argumentName.' ';
if(!empty($argumentDetail[0])){ $argumentString.='= '.$argumentDetail[0]; }

echo str_pad($argumentString,$longestParameter+3,' ').$argumentDetail[1]."\n";
}
echo "\n\n";
}
}

?>

0 comments on commit b02fa1e

Please sign in to comment.