Option.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 StorageConfig $mount
  48. * @param string $key
  49. * @param OutputInterface $output
  50. */
  51. protected function getOption(StorageConfig $mount, $key, OutputInterface $output) {
  52. $value = $mount->getMountOption($key);
  53. if (!is_string($value)) { // show bools and objects correctly
  54. $value = json_encode($value);
  55. }
  56. $output->writeln($value);
  57. }
  58. /**
  59. * @param StorageConfig $mount
  60. * @param string $key
  61. * @param string $value
  62. * @param OutputInterface $output
  63. */
  64. protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) {
  65. $decoded = json_decode($value, true);
  66. if (!is_null($decoded)) {
  67. $value = $decoded;
  68. }
  69. $mount->setMountOption($key, $value);
  70. $this->globalService->updateStorage($mount);
  71. }
  72. }