- Work done on CLI package
This commit is contained in:
1 parent
6d771ed88f
commit
d08d1f0fe7
15 files changed
+482
-38
No files matched your search
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Mcnd\CLI\Option;
|
||||
|
||||
class KeyValueOption extends ParsedOption
|
||||
{
|
||||
protected array $values = [];
|
||||
|
||||
public function setValue(string $key, string $value) : void
|
||||
{
|
||||
$this->values[$key] = $value;
|
||||
}
|
||||
|
||||
public function setRawValue(string $value) : void
|
||||
{
|
||||
if (! str_contains($value, '=')) {
|
||||
throw new \RuntimeException(sprintf("A key=value notation was awaited, received %s instead", $value));
|
||||
}
|
||||
|
||||
list($key, $value) = explode('=', trim($value), 2);
|
||||
|
||||
$this->setValue($key, $value);
|
||||
}
|
||||
|
||||
public function getValue() : null|array
|
||||
{
|
||||
return $this->values ?: null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user