示例#1
0
文件: Script.php 项目: phellow/cli
 /**
  * Start this script.
  *
  * @return int Exit code.
  */
 public function start()
 {
     try {
         $this->params = $this->initParams();
         if (!$this->params instanceof Parameters) {
             $this->params = new Parameters();
             $this->params->ignoreRegisteredOptions = true;
         }
         $this->params->registerOption('help', null, Parameters::VALUE_NO, 'Show help');
         $this->params->parse();
         if ($this->params->get('help')) {
             $this->showHelp($this->params);
         } else {
             $this->run();
         }
         return 0;
     } catch (\Exception $ex) {
         $this->handleException($ex);
         return 1;
     }
 }
示例#2
0
 /**
  * @depends testParse
  */
 public function testGetAll()
 {
     $params = new Parameters();
     $params->registerOption('help', 'h', Parameters::VALUE_NO);
     $params->registerOption('name', null, Parameters::VALUE_YES);
     $_SERVER['argv'] = array('file.php', '-h', '--name=Christian');
     $params->parse();
     $expected = array('help' => true, 'name' => 'Christian');
     $this->assertEquals($expected, $params->getAll());
 }