GetPath.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\App;
  23. use OC\Core\Command\Base;
  24. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  25. use Symfony\Component\Console\Input\InputArgument;
  26. use Symfony\Component\Console\Input\InputInterface;
  27. use Symfony\Component\Console\Output\OutputInterface;
  28. class GetPath extends Base {
  29. protected function configure() {
  30. parent::configure();
  31. $this
  32. ->setName('app:getpath')
  33. ->setDescription('Get an absolute path to the app directory')
  34. ->addArgument(
  35. 'app',
  36. InputArgument::REQUIRED,
  37. 'Name of the app'
  38. )
  39. ;
  40. }
  41. /**
  42. * Executes the current command.
  43. *
  44. * @param InputInterface $input An InputInterface instance
  45. * @param OutputInterface $output An OutputInterface instance
  46. * @return null|int null or 0 if everything went fine, or an error code
  47. */
  48. protected function execute(InputInterface $input, OutputInterface $output) {
  49. $appName = $input->getArgument('app');
  50. $path = \OC_App::getAppPath($appName);
  51. if ($path !== false) {
  52. $output->writeln($path);
  53. return 0;
  54. }
  55. // App not found, exit with non-zero
  56. return 1;
  57. }
  58. /**
  59. * @param string $argumentName
  60. * @param CompletionContext $context
  61. * @return string[]
  62. */
  63. public function completeArgumentValues($argumentName, CompletionContext $context) {
  64. if ($argumentName === 'app') {
  65. return \OC_App::getAllApps();
  66. }
  67. return [];
  68. }
  69. }