Skip to content

Commit 322b496

Browse files
committed
feat: allow loading external storage config values from file
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent fb05f77 commit 322b496

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

apps/files_external/lib/Command/Config.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\AppFramework\Http;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920

2021
class Config extends Base {
@@ -40,7 +41,12 @@ protected function configure(): void {
4041
)->addArgument(
4142
'value',
4243
InputArgument::OPTIONAL,
43-
'value to set the config option to, when no value is provided the existing value will be printed'
44+
'value to set the config option to; when omitted, the existing value is printed; with --value-from-file, this is treated as a file pat'
45+
)->addOption(
46+
'value-from-file',
47+
null,
48+
InputOption::VALUE_NONE,
49+
'treat the value argument as a file path and read the config value from that file'
4450
);
4551
parent::configure();
4652
}
@@ -58,6 +64,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5864

5965
$value = $input->getArgument('value');
6066
if ($value !== null) {
67+
if ($input->getOption('value-from-file')) {
68+
$file = $value;
69+
$value = file_get_contents($file);
70+
if ($value === false) {
71+
$output->writeln('<error>Failed to load value from ' . $file . '</error>');
72+
return 1;
73+
}
74+
}
6175
$this->setOption($mount, $key, $value, $output);
6276
} else {
6377
$this->getOption($mount, $key, $output);

apps/files_external/lib/Command/Option.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OCA\Files_External\Lib\StorageConfig;
1212
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputOption;
1314
use Symfony\Component\Console\Output\OutputInterface;
1415

1516
class Option extends Config {
@@ -29,7 +30,12 @@ protected function configure(): void {
2930
)->addArgument(
3031
'value',
3132
InputArgument::OPTIONAL,
32-
'value to set the mount option to, when no value is provided the existing value will be printed'
33+
'value to set the config option to; when omitted, the existing value is printed; with --value-from-file, this is treated as a file pat'
34+
)->addOption(
35+
'value-from-file',
36+
null,
37+
InputOption::VALUE_NONE,
38+
'treat the value argument as a file path and read the config value from that file'
3339
);
3440
}
3541

0 commit comments

Comments
 (0)