-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add an OCP API for console commands #32780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add an OCP API for console commands
Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
commit 1479c5641ef18bb3b383ab1382972d4879a40e45
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OC\Command; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class SymfonyCommandAdapter extends Command { | ||
|
|
||
| private \OCP\Command\Command $command; | ||
|
|
||
| public function __construct(\OCP\Command\Command $command) { | ||
| parent::__construct($command->getFullyQualifiedName()); | ||
| $this->command = $command; | ||
| } | ||
|
|
||
| protected function configure() { | ||
| parent::configure(); | ||
|
|
||
| $this->setDescription($this->command->getDescription()); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output) { | ||
| $this->command->execute( | ||
| new SymfonyInputAdapter($input), | ||
| new SymfonyOutputAdapter($output) | ||
| ) | ||
| } | ||
|
||
|
|
||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OC\Command; | ||
|
|
||
| use OCP\Command\IInput; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
|
|
||
| class SymfonyInputAdapter implements IInput { | ||
|
|
||
| private InputInterface $input; | ||
|
|
||
| public function __construct(InputInterface $input) { | ||
| $this->input = $input; | ||
| } | ||
|
|
||
| public function isInteractive(): bool { | ||
| return $this->input->isInteractive(); | ||
| } | ||
|
|
||
| public function getArgument(string $name) { | ||
| return $this->input->getArgument($name); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OC\Command; | ||
|
|
||
| use OCP\Command\IOutput; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class SymfonyOutputAdapter implements IOutput { | ||
|
|
||
| private OutputInterface $output; | ||
|
|
||
| public function __construct(OutputInterface $output) { | ||
| $this->output = $output; | ||
| } | ||
|
|
||
| public function formatError(string $message): string { | ||
| return '<error>' . $message . '</error>'; | ||
| } | ||
|
|
||
| public function formatInfo(string $message): string { | ||
| return '<info>' . $message . '</info>'; | ||
| } | ||
|
|
||
| public function writeLn(string $message): void { | ||
| $this->output->writeln($message); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OCP\Command; | ||
|
|
||
| use function implode; | ||
|
|
||
| abstract class Command { | ||
|
|
||
| public const EXIT_CODE_SUCCESS = 0; | ||
| public const EXIT_CODE_ERROR = 1; | ||
|
|
||
| private string $appId; | ||
|
|
||
| public function __construct(string $appId) { | ||
| $this->appId = $appId; | ||
| } | ||
|
|
||
| public function getNamespace(): ?string { | ||
| return $this->appId; | ||
| } | ||
|
|
||
| public abstract function getName(): string; | ||
|
|
||
| public abstract function getDescription(): string; | ||
|
|
||
| public function getFullyQualifiedName(): string { | ||
| if ($this->getNamespace() === null) { | ||
| return $this->getName(); | ||
| } | ||
|
|
||
| return implode(':', [ | ||
| $this->getNamespace(), | ||
| $this->getName() | ||
| ]); | ||
| } | ||
|
|
||
| public function isEnabled(): bool { | ||
| return true; | ||
| } | ||
|
|
||
| public function configure(IConfiguration $config): void { | ||
| } | ||
|
|
||
| public abstract function execute(IInput $input, IOutput $output); | ||
|
|
||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OCP\Command; | ||
|
|
||
| interface IConfiguration { | ||
|
|
||
| public function addArgument(): void; | ||
|
|
||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OCP\Command; | ||
|
|
||
| interface IInput { | ||
|
|
||
| public function isInteractive(): bool; | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getArgument(string $name); | ||
|
|
||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * @copyright 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @author 2022 Christoph Wurst <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OCP\Command; | ||
|
|
||
| interface IOutput { | ||
|
|
||
| public function formatError(string $message): string; | ||
|
|
||
| public function formatInfo(string $message): string; | ||
|
|
||
| public function writeLn(string $message): void; | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / Psalm
InvalidReturnType