pharext\Cli\Args::compile PHP Method

compile() public method

Compile the original spec
public compile ( array | Traversable $spec ) : pharext\Cli\Args
$spec array | Traversable
return pharext\Cli\Args self
    public function compile($spec)
    {
        foreach ($spec as $arg) {
            if (isset($arg[0]) && is_numeric($arg[0])) {
                $arg[3] &= ~0xf00;
                $this->spec["--" . $arg[0]] = $arg;
            } elseif (isset($arg[0])) {
                $this->spec["-" . $arg[0]] = $arg;
                $this->spec["--" . $arg[1]] = $arg;
            } else {
                $this->spec["--" . $arg[1]] = $arg;
            }
            $this->orig[] = $arg;
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testValidate()
 {
     $this->args->compile([["r", "required-option", "This option is required", CliArgs::REQUIRED | CliArgs::NOARG]]);
     foreach ($this->args->parse(0, []) as $error) {
         throw new \Exception("Unexpected parse error: {$error}");
     }
     foreach ($this->args->validate() as $error) {
         $this->assertStringMatchesFormat("%srequired-option%srequired", $error);
     }
     $this->assertTrue(isset($error));
 }