mirror of
https://github.com/mrclay/minify.git
synced 2025-08-21 13:21:59 +02:00
Docs cleanup for MrClay\Cli
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace MrClay;
|
namespace MrClay;
|
||||||
|
|
||||||
|
use MrClay\Cli\Arg;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forms a front controller for a console app, handling and validating arguments (options)
|
* Forms a front controller for a console app, handling and validating arguments (options)
|
||||||
*
|
*
|
||||||
@@ -51,7 +54,7 @@ class Cli {
|
|||||||
public $isHelpRequest = false;
|
public $isHelpRequest = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array of Cli\Arg
|
* @var Arg[]
|
||||||
*/
|
*/
|
||||||
protected $_args = array();
|
protected $_args = array();
|
||||||
|
|
||||||
@@ -80,8 +83,8 @@ class Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cli\Arg|string $letter
|
* @param Arg|string $letter
|
||||||
* @return Cli\Arg
|
* @return Arg
|
||||||
*/
|
*/
|
||||||
public function addOptionalArg($letter)
|
public function addOptionalArg($letter)
|
||||||
{
|
{
|
||||||
@@ -89,8 +92,8 @@ class Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Cli\Arg|string $letter
|
* @param Arg|string $letter
|
||||||
* @return Cli\Arg
|
* @return Arg
|
||||||
*/
|
*/
|
||||||
public function addRequiredArg($letter)
|
public function addRequiredArg($letter)
|
||||||
{
|
{
|
||||||
@@ -100,17 +103,17 @@ class Cli {
|
|||||||
/**
|
/**
|
||||||
* @param string $letter
|
* @param string $letter
|
||||||
* @param bool $required
|
* @param bool $required
|
||||||
* @param Cli\Arg|null $arg
|
* @param Arg|null $arg
|
||||||
* @return Cli\Arg
|
* @return Arg
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function addArgument($letter, $required, Cli\Arg $arg = null)
|
public function addArgument($letter, $required, Arg $arg = null)
|
||||||
{
|
{
|
||||||
if (! preg_match('/^[a-zA-Z]$/', $letter)) {
|
if (! preg_match('/^[a-zA-Z]$/', $letter)) {
|
||||||
throw new \InvalidArgumentException('$letter must be in [a-zA-z]');
|
throw new InvalidArgumentException('$letter must be in [a-zA-Z]');
|
||||||
}
|
}
|
||||||
if (! $arg) {
|
if (! $arg) {
|
||||||
$arg = new Cli\Arg($required);
|
$arg = new Arg($required);
|
||||||
}
|
}
|
||||||
$this->_args[$letter] = $arg;
|
$this->_args[$letter] = $arg;
|
||||||
return $arg;
|
return $arg;
|
||||||
@@ -118,7 +121,7 @@ class Cli {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $letter
|
* @param string $letter
|
||||||
* @return Cli\Arg|null
|
* @return Arg|null
|
||||||
*/
|
*/
|
||||||
public function getArgument($letter)
|
public function getArgument($letter)
|
||||||
{
|
{
|
||||||
@@ -143,7 +146,7 @@ class Cli {
|
|||||||
|
|
||||||
$lettersUsed = '';
|
$lettersUsed = '';
|
||||||
foreach ($this->_args as $letter => $arg) {
|
foreach ($this->_args as $letter => $arg) {
|
||||||
/* @var Cli\Arg $arg */
|
/* @var Arg $arg */
|
||||||
$options .= $letter;
|
$options .= $letter;
|
||||||
$lettersUsed .= $letter;
|
$lettersUsed .= $letter;
|
||||||
|
|
||||||
@@ -159,7 +162,7 @@ class Cli {
|
|||||||
$this->debug['getopt_return'] = $o;
|
$this->debug['getopt_return'] = $o;
|
||||||
|
|
||||||
foreach ($this->_args as $letter => $arg) {
|
foreach ($this->_args as $letter => $arg) {
|
||||||
/* @var Cli\Arg $arg */
|
/* @var Arg $arg */
|
||||||
$this->values[$letter] = false;
|
$this->values[$letter] = false;
|
||||||
if (isset($o[$letter])) {
|
if (isset($o[$letter])) {
|
||||||
if (is_bool($o[$letter])) {
|
if (is_bool($o[$letter])) {
|
||||||
@@ -295,7 +298,7 @@ class Cli {
|
|||||||
{
|
{
|
||||||
$r = "\n";
|
$r = "\n";
|
||||||
foreach ($this->_args as $letter => $arg) {
|
foreach ($this->_args as $letter => $arg) {
|
||||||
/* @var Cli\Arg $arg */
|
/* @var Arg $arg */
|
||||||
$desc = $arg->getDescription();
|
$desc = $arg->getDescription();
|
||||||
$flag = " -$letter ";
|
$flag = " -$letter ";
|
||||||
if ($arg->mayHaveValue) {
|
if ($arg->mayHaveValue) {
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace MrClay\Cli;
|
namespace MrClay\Cli;
|
||||||
|
|
||||||
|
use BadMethodCallException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument for a CLI app. This specifies the argument, what values it expects and
|
* An argument for a CLI app. This specifies the argument, what values it expects and
|
||||||
* how it's treated during validation.
|
* how it's treated during validation.
|
||||||
@@ -150,7 +152,7 @@ class Arg {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @return Arg
|
* @return Arg
|
||||||
* @throws \BadMethodCallException
|
* @throws BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function __call($name, array $args = array())
|
public function __call($name, array $args = array())
|
||||||
{
|
{
|
||||||
@@ -160,7 +162,7 @@ class Arg {
|
|||||||
$this->spec['mustHaveValue'] = true;
|
$this->spec['mustHaveValue'] = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \BadMethodCallException('Method does not exist');
|
throw new BadMethodCallException('Method does not exist');
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user