NewProjectCommand.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @package Grav\Console\Cli
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Console\Cli;
  9. use Grav\Console\ConsoleCommand;
  10. use Symfony\Component\Console\Input\ArrayInput;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputOption;
  13. class NewProjectCommand extends ConsoleCommand
  14. {
  15. protected function configure()
  16. {
  17. $this
  18. ->setName('new-project')
  19. ->setAliases(['newproject'])
  20. ->addArgument(
  21. 'destination',
  22. InputArgument::REQUIRED,
  23. 'The destination directory of your new Grav project'
  24. )
  25. ->addOption(
  26. 'symlink',
  27. 's',
  28. InputOption::VALUE_NONE,
  29. 'Symlink the required bits'
  30. )
  31. ->setDescription('Creates a new Grav project with all the dependencies installed')
  32. ->setHelp("The <info>new-project</info> command is a combination of the `setup` and `install` commands.\nCreates a new Grav instance and performs the installation of all the required dependencies.");
  33. }
  34. protected function serve()
  35. {
  36. $sandboxCommand = $this->getApplication()->find('sandbox');
  37. $installCommand = $this->getApplication()->find('install');
  38. $sandboxArguments = new ArrayInput([
  39. 'command' => 'sandbox',
  40. 'destination' => $this->input->getArgument('destination'),
  41. '-s' => $this->input->getOption('symlink')
  42. ]);
  43. $installArguments = new ArrayInput([
  44. 'command' => 'install',
  45. 'destination' => $this->input->getArgument('destination'),
  46. '-s' => $this->input->getOption('symlink')
  47. ]);
  48. $sandboxCommand->run($sandboxArguments, $this->output);
  49. $installCommand->run($installArguments, $this->output);
  50. }
  51. }