Skip to content
Permalink
Browse files

Pulling out some duplicated code into methods.

  • Loading branch information...
markstory committed Oct 10, 2010
1 parent 5e8222e commit 8261581b3b7584b6f8f7ae68e931a11da901265d
Showing with 24 additions and 10 deletions.
  1. +9 −0 cake/console/console_input_option.php
  2. +15 −10 cake/console/console_option_parser.php
@@ -53,6 +53,15 @@ public function __construct($name, $short = null, $help = '', $boolean = false,
}
}
/**
* Get the name of the argument
*
* @return string
*/
public function name() {
return $this->name;
}
/**
* Generate the help for this this option.
*
@@ -390,11 +390,7 @@ public function help($subcommand = null) {
}
if (!empty($this->_options)) {
$max = 0;
foreach ($this->_options as $description) {
$max = (strlen($description->name) > $max) ? strlen($description->name) : $max;
}
$max += 8;
$max = $this->_getMaxLength($this->_options) + 8;
$out[] = '<info>Options:</info>';
$out[] = '';
foreach ($this->_options as $option) {
@@ -403,11 +399,7 @@ public function help($subcommand = null) {
$out[] = '';
}
if (!empty($this->_args)) {
$max = 0;
foreach ($this->_args as $argument) {
$max = (strlen($argument->name) > $max) ? strlen($argument->name) : $max;
}
$max += 2;
$max = $this->_getMaxLength($this->_args) + 2;
$out[] = '<info>Arguments:</info>';
$out[] = '';
foreach ($this->_args as $argument) {
@@ -547,4 +539,17 @@ protected function _parseArg($argument, $args) {
protected function _nextToken() {
return isset($this->_tokens[0]) ? $this->_tokens[0] : '';
}
/**
* Iterate over a collection and find the longest named thing.
*
* @return integer
*/
protected function _getMaxLength($collection) {
$max = 0;
foreach ($collection as $item) {
$max = (strlen($item->name()) > $max) ? strlen($item->name()) : $max;
}
return $max;
}
}

0 comments on commit 8261581

Please sign in to comment.
You can’t perform that action at this time.