You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\App;
  8. use OC\Core\Command\Base;
  9. use OCP\App\AppPathNotFoundException;
  10. use OCP\App\IAppManager;
  11. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class GetPath extends Base {
  16. public function __construct(
  17. protected IAppManager $appManager,
  18. ) {
  19. parent::__construct();
  20. }
  21. protected function configure(): void {
  22. parent::configure();
  23. $this
  24. ->setName('app:getpath')
  25. ->setDescription('Get an absolute path to the app directory')
  26. ->addArgument(
  27. 'app',
  28. InputArgument::REQUIRED,
  29. 'Name of the app'
  30. )
  31. ;
  32. }
  33. /**
  34. * Executes the current command.
  35. *
  36. * @param InputInterface $input An InputInterface instance
  37. * @param OutputInterface $output An OutputInterface instance
  38. * @return int 0 if everything went fine, or an error code
  39. */
  40. protected function execute(InputInterface $input, OutputInterface $output): int {
  41. $appName = $input->getArgument('app');
  42. try {
  43. $path = $this->appManager->getAppPath($appName);
  44. } catch (AppPathNotFoundException) {
  45. // App not found, exit with non-zero
  46. return self::FAILURE;
  47. }
  48. $output->writeln($path);
  49. return self::SUCCESS;
  50. }
  51. /**
  52. * @param string $argumentName
  53. * @param CompletionContext $context
  54. * @return string[]
  55. */
  56. public function completeArgumentValues($argumentName, CompletionContext $context): array {
  57. if ($argumentName === 'app') {
  58. return \OC_App::getAllApps();
  59. }
  60. return [];
  61. }
  62. }