Skip to content

Commit 0b35871

Browse files
committed
update ...
1 parent bf2e31f commit 0b35871

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

examples/TestCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestCommand extends Command
1818
{
1919
/**
2020
* test text
21-
* @usage {$name} test message
21+
* @usage {name} test message
2222
*/
2323
public function execute($input, $output)
2424
{

src/AbstractApp.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ public function config($name, $default = null)
510510
* set config
511511
* @param array $config
512512
*/
513-
public function setConfig(array $config)
513+
public function setConfig($config)
514514
{
515515
if ($config) {
516-
$this->config = array_merge($this->config, $config);
516+
$this->config = array_merge($this->config, (array)$config);
517517
}
518518
}
519519

@@ -532,6 +532,6 @@ public function getConfig()
532532
*/
533533
public function isDebug(): bool
534534
{
535-
return (bool) $this->config['debug'];
535+
return (bool) $this->config('debug');
536536
}
537537
}

src/AbstractCommand.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,40 @@ public function validate()
9999
return true;
100100
}
101101

102-
$givenArgs = $this->input->getArgs();
102+
$givenArgs = $errArgs = [];
103103

104-
$missingArgs = array_filter(array_keys($definition->getArguments()), function ($name) use ($definition, $givenArgs) {
104+
foreach ($this->input->getArgs() as $key => $value) {
105+
if (is_int($key)) {
106+
$givenArgs[$key] = $value;
107+
} else {
108+
$errArgs[] = $key;
109+
}
110+
}
111+
112+
if (count($errArgs) > 0) {
113+
throw new \RuntimeException(sprintf('Unknown arguments (error: "%s").', implode(', ', $errArgs)));
114+
}
115+
116+
$defArgs = $definition->getArguments();
117+
118+
$missingArgs = array_filter(array_keys($defArgs), function ($name) use ($definition, $givenArgs) {
105119
return !array_key_exists($name, $givenArgs) && $definition->argumentIsRequired($name);
106120
});
107121

108122
if (count($missingArgs) > 0) {
109123
throw new \RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArgs)));
110124
}
111125

126+
$index = 0;
127+
$args = [];
128+
129+
foreach ($defArgs as $name => $conf) {
130+
$args[$name] = $givenArgs[$index];
131+
$index++;
132+
}
133+
134+
$this->input->setArgs($args);
135+
112136
return true;
113137
}
114138

src/App.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
*/
1515
class App extends AbstractApp
1616
{
17+
/**
18+
* addCommand
19+
* @param string $name
20+
* @param mixed $controller
21+
*/
22+
public function addCommand(string $name, $handler = null)
23+
{
24+
return $this->command($name, $handler);
25+
}
26+
27+
/**
28+
* addGroup
29+
* @param string $name
30+
* @param string|null $controller
31+
*/
32+
public function addGroup(string $name, string $controller = null)
33+
{
34+
return $this->controller($name, $controller);
35+
}
36+
1737
/**********************************************************
1838
* dispatch and run console controller/command
1939
**********************************************************/

src/io/Input.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,11 @@ public function getArgs(): array
433433

434434
/**
435435
* @param array $args
436+
* @param bool $replace
436437
*/
437-
public function setArgs(array $args)
438+
public function setArgs(array $args, $replace = false)
438439
{
439-
$this->args = $args;
440+
$this->args = $replace ? $args : array_merge($this->args, $args);
440441
}
441442

442443
/**
@@ -457,10 +458,11 @@ public function getSOpts(): array
457458

458459
/**
459460
* @param array $sOpts
461+
* @param bool $replace
460462
*/
461-
public function setSOpts(array $sOpts)
463+
public function setSOpts(array $sOpts, $replace = false)
462464
{
463-
$this->sOpts = $sOpts;
465+
$this->sOpts = $replace ? $sOpts : array_merge($this->sOpts, $sOpts);
464466
}
465467

466468
/**
@@ -481,10 +483,11 @@ public function getLOpts(): array
481483

482484
/**
483485
* @param array $lOpts
486+
* @param bool $replace
484487
*/
485-
public function setLOpts(array $lOpts)
488+
public function setLOpts(array $lOpts, $replace = false)
486489
{
487-
$this->lOpts = $lOpts;
490+
$this->lOpts = $replace ? $lOpts : array_merge($this->lOpts, $lOpts);
488491
}
489492

490493
/**

0 commit comments

Comments
 (0)