Esempio n. 1
0
 /**
  * Execute the Help option
  *
  * @param array $argumentData Argument data
  *
  * @return bool Stop/Don't stop execution
  */
 public function execute($argumentData)
 {
     \Usher\Lib\Console\Output::msg('Help Information:');
     /**
      * look through all of our option and find the 
      * docblock comments with their description
      */
     $iterator = new \DirectoryIterator(__DIR__);
     $optionMaxLength = 0;
     $options = array();
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->isFile()) {
             // include the file so we can get it's class
             $fileName = str_replace('.php', '', $fileinfo->getFilename());
             $className = '\\Usher\\Lib\\Console\\Option\\' . $fileName;
             include_once $fileinfo->getPathname();
             $ref = new \ReflectionClass($className);
             $comment = $ref->getDocComment();
             //see if we have a
             if (preg_match('/@description(.+)/', $comment, $matches) !== false) {
                 $options[strtolower($fileName)] = trim($matches[1]);
                 if (strlen($fileName) > $optionMaxLength) {
                     $optionMaxLength = strlen($fileName);
                 }
             }
         }
     }
     // now echo out our options
     if (!empty($options)) {
         // pad out the value to our max length
         foreach ($options as $keyName => $option) {
             echo ' --' . str_pad($keyName, $optionMaxLength + 1, " ", STR_PAD_RIGHT) . ' : ' . $option . "\n";
         }
     }
     //and one last line for good luck
     echo "\n";
     return false;
 }
Esempio n. 2
0
 /**
  * Parse the current options given on the command line
  *
  * @return void
  */
 private static function _parseArguments()
 {
     $args = $_SERVER['argv'];
     // go through our options and see if any of them are defined
     // remove the first since it's the script's name
     $arguments = isset($_SERVER['argv']) && !empty($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1, count($_SERVER['argv']) - 1) : array();
     foreach ($arguments as $argument) {
         // remove the "-" or "--", but only at the beginning
         $argument = preg_replace('/^\\-+/', '', $argument);
         // split off the key/value
         $parts = explode('=', $argument);
         $argument = !is_array($parts) ? array($parts) : $parts;
         // see if we have a class to match it
         $nsPath = '\\Usher\\Lib\\Console\\Option\\' . ucwords(strtolower($argument[0]));
         try {
             try {
                 $stopExecution = $nsPath::execute($argument);
                 if ($stopExecution == false) {
                     die;
                 }
             } catch (\RuntimeException $re) {
                 \Usher\Lib\Console\Output::msg($re->getMessage());
                 if ($stopExecution == false) {
                     die;
                 }
             }
         } catch (\Exception $e) {
             // can't find the argument class
             \Usher\Lib\Console\Output::msg('Option "' . $argument[0] . '" not found.');
         }
     }
 }