Option.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_External\Command;
  24. use OCA\Files_External\Lib\StorageConfig;
  25. use Symfony\Component\Console\Input\InputArgument;
  26. use Symfony\Component\Console\Output\OutputInterface;
  27. class Option extends Config {
  28. protected function configure(): void {
  29. $this
  30. ->setName('files_external:option')
  31. ->setDescription('Manage mount options for a mount')
  32. ->addArgument(
  33. 'mount_id',
  34. InputArgument::REQUIRED,
  35. 'The id of the mount to edit'
  36. )->addArgument(
  37. 'key',
  38. InputArgument::REQUIRED,
  39. 'key of the mount option to set/get'
  40. )->addArgument(
  41. 'value',
  42. InputArgument::OPTIONAL,
  43. 'value to set the mount option to, when no value is provided the existing value will be printed'
  44. );
  45. }
  46. /**
  47. * @param string $key
  48. */
  49. protected function getOption(StorageConfig $mount, $key, OutputInterface $output): void {
  50. $value = $mount->getMountOption($key);
  51. if (!is_string($value)) { // show bools and objects correctly
  52. $value = json_encode($value);
  53. }
  54. $output->writeln($value);
  55. }
  56. /**
  57. * @param string $key
  58. * @param string $value
  59. */
  60. protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output): void {
  61. $decoded = json_decode($value, true);
  62. if (!is_null($decoded)) {
  63. $value = $decoded;
  64. }
  65. $mount->setMountOption($key, $value);
  66. $this->globalService->updateStorage($mount);
  67. }
  68. }