GetOptionKit\OptionCollection::all PHP Method

all() public method

public all ( )
    public function all()
    {
        return $this->data;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Prints a the program help
  *
  * @param array                           $cmdDef
  * @param \GetOptionKit\OptionCollection  $specs
  */
 private function printHelp($cmdDef, $specs)
 {
     $reqArgs = array_map('strtoupper', $cmdDef['args']['required']);
     $optArgs = array_map(function ($arg) {
         return '[' . strtoupper($arg) . ']';
     }, $cmdDef['args']['optional']);
     $args = array_merge($reqArgs, $optArgs);
     $argNames = implode(' ', $args);
     echo "Usage: {$this->progPath} {$this->cmd} [OPTION] {$argNames}\n";
     echo "{$cmdDef['title']}\n";
     if (isset($cmdDef['help'])) {
         echo "{$cmdDef['help']}\n";
     }
     echo "\n";
     $widths = array_map(function ($spec) {
         return strlen($spec->renderReadableSpec());
     }, $specs->all());
     $width = max($widths);
     $lines = [];
     foreach ($specs->all() as $spec) {
         $c1 = str_pad($spec->renderReadableSpec(), $width);
         $line = sprintf("%s  %s", $c1, $spec->desc);
         $lines[] = $line;
     }
     foreach ($lines as $line) {
         $line = trim($line);
         echo " {$line}\n";
     }
 }