]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow array recursion in get
authorJoas Schilling <nickvergessen@owncloud.com>
Wed, 9 Dec 2015 13:47:28 +0000 (14:47 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Thu, 14 Jan 2016 14:02:55 +0000 (15:02 +0100)
core/command/config/system/getconfig.php
tests/core/command/config/system/getconfigtest.php

index 80b41a68526cd2928f9afcf50461a7351bbea3d0..b76474112a08549945601ae7d4cc090fac92222b 100644 (file)
@@ -48,8 +48,8 @@ class GetConfig extends Base {
                        ->setDescription('Get a system config value')
                        ->addArgument(
                                'name',
-                               InputArgument::REQUIRED,
-                               'Name of the config to get'
+                               InputArgument::REQUIRED | InputArgument::IS_ARRAY,
+                               'Name of the config to get, specify multiple for array parameter'
                        )
                        ->addOption(
                                'default-value',
@@ -68,7 +68,8 @@ class GetConfig extends Base {
         * @return null|int null or 0 if everything went fine, or an error code
         */
        protected function execute(InputInterface $input, OutputInterface $output) {
-               $configName = $input->getArgument('name');
+               $configNames = $input->getArgument('name');
+               $configName = array_shift($configNames);
                $defaultValue = $input->getOption('default-value');
 
                if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) {
@@ -79,6 +80,18 @@ class GetConfig extends Base {
                        $configValue = $defaultValue;
                } else {
                        $configValue = $this->systemConfig->getValue($configName);
+                       if (!empty($configNames)) {
+                               foreach ($configNames as $configName) {
+                                       if (isset($configValue[$configName])) {
+                                               $configValue = $configValue[$configName];
+                                       } else if (!$input->hasParameterOption('--default-value')) {
+                                               return 1;
+                                       } else {
+                                               $configValue = $defaultValue;
+                                               break;
+                                       }
+                               }
+                       }
                }
 
                $this->writeMixedInOutputFormat($input, $output, $configValue);
index 54dcdd434abc189b2d3085e49ee192d48a6f232a..ebbea634cde597414aa27468de0dcf2fc8b8e3f9 100644 (file)
@@ -90,13 +90,19 @@ class GetConfigTest extends TestCase {
                        ['name', ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(['a' => 1, 'b' => 2])],
                        ['name', ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, "a: 1\nb: 2"],
 
+                       // Nested depth
+                       [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(1)],
+                       [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, '1'],
+                       [['name', 'c'], ['a' => 1, 'b' => 2], true, true, true, 'json', 0, json_encode(true)],
+                       [['name', 'c'], ['a' => 1, 'b' => 2], true, true, false, 'json', 1, null],
+
                ];
        }
 
        /**
         * @dataProvider getData
         *
-        * @param string $configName
+        * @param string[] $configNames
         * @param mixed $value
         * @param bool $configExists
         * @param mixed $defaultValue
@@ -105,7 +111,13 @@ class GetConfigTest extends TestCase {
         * @param int $expectedReturn
         * @param string $expectedMessage
         */
-       public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+       public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+               if (is_array($configNames)) {
+                       $configName = $configNames[0];
+               } else {
+                       $configName = $configNames;
+                       $configNames = [$configName];
+               }
                $this->systemConfig->expects($this->atLeastOnce())
                        ->method('getKeys')
                        ->willReturn($configExists ? [$configName] : []);
@@ -122,7 +134,7 @@ class GetConfigTest extends TestCase {
                $this->consoleInput->expects($this->once())
                        ->method('getArgument')
                        ->with('name')
-                       ->willReturn($configName);
+                       ->willReturn($configNames);
                $this->consoleInput->expects($this->any())
                        ->method('getOption')
                        ->willReturnMap([