option() public method

Gets/Sets/Overrides an option's attributes.
public option ( string $name = null, array $config = [], $value = null ) : array
$name string The name of the option.
$config array The option attributes to set.
return array
Beispiel #1
0
 /**
  * Load the config.
  *
  * @param string $argv The command line string.
  */
 public function loadConfig($argv = [])
 {
     $commandLine = new CommandLine();
     $commandLine->option('config', ['default' => 'kahlan-config.php']);
     $commandLine->option('help', ['type' => 'boolean']);
     $commandLine->option('version', ['type' => 'boolean']);
     $commandLine->parse($argv);
     $run = function ($commandLine) {
         if (file_exists($commandLine->get('config'))) {
             require $commandLine->get('config');
         }
     };
     $run($commandLine);
     $this->_commandLine->parse($argv, false);
     if ($commandLine->get('help')) {
         return $this->_help();
     }
     if ($commandLine->get('version')) {
         return $this->_version();
     }
 }
Beispiel #2
0
         expect($commandLine->get('option1'))->toBe([]);
     });
 });
 describe("->exists()", function () {
     it("returns `true` if the option exists", function () {
         $commandLine = new CommandLine();
         $actual = $commandLine->parse(['command', '--option1', '--option2=true', '--option3=false', '--option4=0']);
         expect($commandLine->exists('option1'))->toBe(true);
         expect($commandLine->exists('option2'))->toBe(true);
         expect($commandLine->exists('option3'))->toBe(true);
         expect($commandLine->exists('option4'))->toBe(true);
         expect($commandLine->exists('option5'))->toBe(false);
     });
     it("returns `true` if the option as a default value", function () {
         $commandLine = new CommandLine();
         $commandLine->option('option1', ['type' => 'boolean']);
         $commandLine->option('option2', ['type' => 'boolean', 'default' => false]);
         expect($commandLine->exists('option1'))->toBe(false);
         expect($commandLine->exists('option2'))->toBe(true);
     });
 });
 describe("->cast()", function () {
     it("casts array", function () {
         $commandLine = new CommandLine();
         $cast = $commandLine->cast(["some", "string", "and", 10], "string");
         expect($cast)->toBeAn('array');
         foreach ($cast as $c) {
             expect($c)->toBeA('string');
         }
     });
     it("casts boolean", function () {