Use argument instead of value

This commit is contained in:
Joas Schilling 2016-07-14 15:09:47 +02:00
parent 4656b79c8e
commit aaf2be4c3d
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 30 additions and 32 deletions

View File

@ -90,11 +90,11 @@ class Setting extends Base {
)
// Set
->addOption(
->addArgument(
'value',
null,
InputOption::VALUE_REQUIRED,
'The new value of the setting'
InputArgument::OPTIONAL,
'The new value of the setting',
null
)
->addOption(
'update-only',
@ -129,13 +129,13 @@ class Setting extends Base {
throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.');
}
if ($input->getArgument('key') === '' && $input->hasParameterOption('--value')) {
throw new \InvalidArgumentException('The "value" option can only be used when specifying a key.');
if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) {
throw new \InvalidArgumentException('The value argument can only be used when specifying a key.');
}
if ($input->hasParameterOption('--value') && $input->hasParameterOption('--default-value')) {
throw new \InvalidArgumentException('The "value" option can not be used together with "default-value".');
if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) {
throw new \InvalidArgumentException('The value argument can not be used together with "default-value".');
}
if ($input->getOption('update-only') && !$input->hasParameterOption('--value')) {
if ($input->getOption('update-only') && $input->getArgument('value') === null) {
throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".');
}
@ -145,7 +145,7 @@ class Setting extends Base {
if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) {
throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".');
}
if ($input->getOption('delete') && $input->hasParameterOption('--value')) {
if ($input->getOption('delete') && $input->getArgument('value') !== null) {
throw new \InvalidArgumentException('The "delete" option can not be used together with "value".');
}
if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) {
@ -167,13 +167,13 @@ class Setting extends Base {
if ($key !== '') {
$value = $this->config->getUserValue($uid, $app, $key, null);
if ($input->hasParameterOption('--value')) {
if ($input->getArgument('value') !== null) {
if ($input->hasParameterOption('--update-only') && $value === null) {
$output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
return 1;
}
$this->config->setUserValue($uid, $app, $key, $input->getOption('value'));
$this->config->setUserValue($uid, $app, $key, $input->getArgument('value'));
return 0;
} else if ($input->hasParameterOption('--delete')) {

View File

@ -107,37 +107,37 @@ class SettingTest extends TestCase {
],
[
[['uid', 'username'], ['key', 'configkey']],
[['uid', 'username'], ['key', 'configkey'], ['value', '']],
[['ignore-missing-user', true]],
[['--value', true]],
[],
false,
false,
],
[
[['uid', 'username'], ['key', '']],
[['uid', 'username'], ['key', ''], ['value', '']],
[['ignore-missing-user', true]],
[['--value', true]],
[],
false,
'The "value" option can only be used when specifying a key.',
'The value argument can only be used when specifying a key.',
],
[
[['uid', 'username'], ['key', 'configkey']],
[['uid', 'username'], ['key', 'configkey'], ['value', '']],
[['ignore-missing-user', true]],
[['--value', true], ['--default-value', true]],
[['--default-value', true]],
false,
'The "value" option can not be used together with "default-value".',
'The value argument can not be used together with "default-value".',
],
[
[['uid', 'username'], ['key', 'configkey']],
[['uid', 'username'], ['key', 'configkey'], ['value', '']],
[['ignore-missing-user', true], ['update-only', true]],
[['--value', true]],
[],
false,
false,
],
[
[['uid', 'username'], ['key', 'configkey']],
[['uid', 'username'], ['key', 'configkey'], ['value', null]],
[['ignore-missing-user', true], ['update-only', true]],
[['--value', false]],
[],
false,
'The "update-only" option can only be used together with "value".',
],
@ -164,9 +164,9 @@ class SettingTest extends TestCase {
'The "delete" option can not be used together with "default-value".',
],
[
[['uid', 'username'], ['key', 'configkey']],
[['uid', 'username'], ['key', 'configkey'], ['value', '']],
[['ignore-missing-user', true], ['delete', true]],
[['--value', true]],
[],
false,
'The "delete" option can not be used together with "value".',
],
@ -324,12 +324,13 @@ class SettingTest extends TestCase {
'getUserSettings',
]);
$this->consoleInput->expects($this->any())
$this->consoleInput->expects($this->atLeast(4))
->method('getArgument')
->willReturnMap([
['uid', 'username'],
['app', 'appname'],
['key', 'configkey'],
['value', 'setValue'],
]);
$command->expects($this->once())
@ -343,7 +344,6 @@ class SettingTest extends TestCase {
$this->consoleInput->expects($this->atLeastOnce())
->method('hasParameterOption')
->willReturnMap([
['--value', true],
['--update-only', $updateOnly],
]);
@ -351,10 +351,8 @@ class SettingTest extends TestCase {
$this->consoleOutput->expects($this->never())
->method('writeln');
$this->consoleInput->expects($this->once())
->method('getOption')
->with('value')
->willReturn('setValue');
$this->consoleInput->expects($this->never())
->method('getOption');
$this->config->expects($this->once())
->method('setUserValue')