-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxence Lange <[email protected]>
- Loading branch information
1 parent
d8e625f
commit d0c05cd
Showing
24 changed files
with
2,460 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* | ||
* @author Joas Schilling <[email protected]> | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -21,15 +24,16 @@ | |
*/ | ||
namespace OC\Core\Command\Config\App; | ||
|
||
use OCP\IConfig; | ||
use OCP\Exceptions\AppConfigUnknownKeyException; | ||
use OCP\IAppConfig; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class GetConfig extends Base { | ||
public function __construct( | ||
protected IConfig $config, | ||
protected IAppConfig $appConfig, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
@@ -50,6 +54,12 @@ protected function configure() { | |
InputArgument::REQUIRED, | ||
'Name of the config to get' | ||
) | ||
->addOption( | ||
'details', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'returns complete details about the app config value' | ||
) | ||
->addOption( | ||
'default-value', | ||
null, | ||
|
@@ -71,14 +81,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$configName = $input->getArgument('name'); | ||
$defaultValue = $input->getOption('default-value'); | ||
|
||
if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) { | ||
return 1; | ||
if ($input->getOption('details')) { | ||
$details = $this->appConfig->getDetails($appName, $configName); | ||
$format = $input->getOption('output') ?? 'plain'; | ||
if ($format === 'json') { | ||
$output->writeln(json_encode($details)); | ||
} elseif ($format === 'json_pretty') { | ||
$output->writeln(json_encode($details, JSON_PRETTY_PRINT)); | ||
} else { | ||
$output->writeln('App: ' . $details['app'] ?? ''); | ||
$output->writeln('Config Key: ' . $details['key'] ?? ''); | ||
$output->writeln('Config Value: ' . $details['value'] ?? ''); | ||
$output->writeln('Value type: ' . $details['typeString'] ?? ''); | ||
$output->writeln('Lazy loaded: ' . (($details['lazy'] ?? false) ? 'Yes' : 'No')); | ||
$output->writeln('Sensitive: ' . (($details['sensitive'] ?? false) ? 'Yes' : 'No')); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
if (!in_array($configName, $this->config->getAppKeys($appName))) { | ||
try { | ||
$configValue = $this->appConfig->getDetails($appName, $configName)['value']; | ||
} catch (AppConfigUnknownKeyException $e) { | ||
if (!$input->hasParameterOption('--default-value')) { | ||
return 1; | ||
} | ||
$configValue = $defaultValue; | ||
} else { | ||
$configValue = $this->config->getAppValue($appName, $configName); | ||
} | ||
|
||
$this->writeMixedInOutputFormat($input, $output, $configValue); | ||
|
Oops, something went wrong.