Exemple #1
0
 private static function handleArguments($args)
 {
     $scriptName = array_shift($args);
     if (count($args) == 0) {
         echo self::getHelp();
     } elseif ($args[0][0] == '-') {
         $parser = new OptionParser(self::getOptions());
         list($opts, $nonOpts) = $parser->parseArgs($args);
         if (isset($opts['version'])) {
             echo 'stato version ' . self::$version . "\n";
         }
         if (isset($opts['help'])) {
             $command = self::getCommand($opts['help']);
             if (!$command) {
                 echo "stato: '{$opts['help']}' is not a stato command. See 'stato --help'.\n";
             } else {
                 echo $command->getHelp();
             }
         }
     } else {
         $commandName = array_shift($args);
         $command = self::getCommand($commandName);
         if (!$command) {
             echo "stato: '{$commandName}' is not a stato command. See 'stato --help'.\n";
             return;
         }
         $parser = new OptionParser($command->getOptions());
         list($opts, $nonOpts) = $parser->parseArgs($args);
         $command->run($opts, $nonOpts);
     }
 }