Option.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Command;
  8. use OCA\Files_External\Lib\StorageConfig;
  9. use Symfony\Component\Console\Input\InputArgument;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. class Option extends Config {
  12. protected function configure(): void {
  13. $this
  14. ->setName('files_external:option')
  15. ->setDescription('Manage mount options for a mount')
  16. ->addArgument(
  17. 'mount_id',
  18. InputArgument::REQUIRED,
  19. 'The id of the mount to edit'
  20. )->addArgument(
  21. 'key',
  22. InputArgument::REQUIRED,
  23. 'key of the mount option to set/get'
  24. )->addArgument(
  25. 'value',
  26. InputArgument::OPTIONAL,
  27. 'value to set the mount option to, when no value is provided the existing value will be printed'
  28. );
  29. }
  30. /**
  31. * @param string $key
  32. */
  33. protected function getOption(StorageConfig $mount, $key, OutputInterface $output): void {
  34. $value = $mount->getMountOption($key);
  35. if (!is_string($value)) { // show bools and objects correctly
  36. $value = json_encode($value);
  37. }
  38. $output->writeln($value);
  39. }
  40. /**
  41. * @param string $key
  42. * @param string $value
  43. */
  44. protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output): void {
  45. $decoded = json_decode($value, true);
  46. if (!is_null($decoded)) {
  47. $value = $decoded;
  48. }
  49. $mount->setMountOption($key, $value);
  50. $this->globalService->updateStorage($mount);
  51. }
  52. }