parse() 공개 메소드

Parses a command line argv.
public parse ( array $argv, boolean $override = true ) : array
$argv array An argv data.
$override boolean If set to `false` it doesn't override already setted data.
리턴 array The parsed attributes
예제 #1
0
파일: Kahlan.php 프로젝트: crysalead/kahlan
 /**
  * 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();
     }
 }
예제 #2
0
     });
     it("returns a group subset even when no explicitly defined", function () {
         $commandLine = new CommandLine();
         $actual = $commandLine->parse(['command', '--option1:sub1=value1', '--option1:sub2=value2']);
         expect($commandLine->get('option1'))->toBe(['sub1' => 'value1', 'sub2' => 'value2']);
     });
     it("returns an array by default for group subsets", function () {
         $commandLine = new CommandLine(['option1:sub1' => ['array' => true]]);
         $actual = $commandLine->parse(['command']);
         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 () {