Esempio n. 1
0
 /**
  * This is it, we parse the given arguments.
  *
  * @throws \Exception
  */
 public function parse()
 {
     list($shortOptions, $longOptions) = $this->buildOptions();
     $results = getopt($shortOptions, $longOptions);
     foreach ($this->arguments as $argument) {
         $name = $argument->name;
         $value = '';
         if (isset($results[$argument->prefix]) || isset($results[$argument->longPrefix])) {
             $value = isset($results[$argument->prefix]) ? $results[$argument->prefix] : $results[$argument->longPrefix];
         } else {
             /**
              * If we set the default value for this argument we also add it to
              * the result array or it will fail the argument has the option required by mistake.
              */
             if ($argument->defaultValue) {
                 $value = $argument->defaultValue;
                 $this->manager->setHasDefaultValue($name, true);
                 $results[$argument->name] = $value;
             } else {
                 if ($argument->required === true) {
                     throw new \Exception('The following arguments are required: ' . print_r($argument->name, true) . '.');
                 }
             }
         }
         $this->manager->set($name, $value);
     }
 }
Esempio n. 2
0
 /**
  * Test if a value being set is retrievable via \Redbox\Cli\Arguments\Manager::get
  */
 public function test_if_get_returns_the_same_as_been_set()
 {
     $manager = new Arguments\Manager();
     $manager->set('key', 'val');
     $this->assertEquals($manager->get('key'), 'val');
 }