Skip to content

Commit

Permalink
Add option on setup to execute commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Sanchez committed Nov 30, 2017
1 parent a184448 commit 34d553e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DalaiLomo\ACE\Helper\FileHandler;
use DalaiLomo\ACE\Setup\Menu\InteractiveMenu;
use DalaiLomo\ACE\Setup\Section\EditConfigurationFileSection;
use DalaiLomo\ACE\Setup\Section\ExecutorSection;
use DalaiLomo\ACE\Setup\Section\ListCommandGroupsSection;
use DalaiLomo\ACE\Setup\Section\LogViewerSection;
use Symfony\Component\Console\Command\Command;
Expand All @@ -29,8 +30,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$interactiveMenu = new InteractiveMenu($input, $output, $this->getHelper('question'), $config);

$interactiveMenu->registerSection(new ListCommandGroupsSection());
$interactiveMenu->registerSection(new EditConfigurationFileSection());
$interactiveMenu->registerSection(new ExecutorSection());
$interactiveMenu->registerSection(new LogViewerSection());
$interactiveMenu->registerSection(new EditConfigurationFileSection());

$interactiveMenu->run();

Expand Down
30 changes: 30 additions & 0 deletions src/Setup/Section/ExecutorSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace DalaiLomo\ACE\Setup\Section;

use DalaiLomo\ACE\Helper\CommandOutputHelper;
use DalaiLomo\ACE\Setup\Menu\InteractiveMenu;
use DalaiLomo\ACE\Setup\Section\ExecutorSection\ExecutorGroupSection;
use Symfony\Component\Console\Question\Question;

class ExecutorSection extends AbstractSection
{
public function getSectionName()
{
return 'Execute group';
}

public function doAction()
{
$interactiveMenu = new InteractiveMenu($this->input, $this->output, $this->question, $this->config);
$interactiveMenu->setOptionQuitText('Back to main menu');

$this->config->onEachKey(function($groups, $key) use ($interactiveMenu) {
$interactiveMenu->registerSection(new ExecutorGroupSection($groups, $key));
});

$interactiveMenu->run();

$this->output->writeln(CommandOutputHelper::clearOutput());
}
}
53 changes: 53 additions & 0 deletions src/Setup/Section/ExecutorSection/ExecutorGroupSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace DalaiLomo\ACE\Setup\Section\ExecutorSection;

use DalaiLomo\ACE\Command\ExecuteCommand;
use DalaiLomo\ACE\Helper\CommandOutputHelper;
use DalaiLomo\ACE\Setup\Section\AbstractSection;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\StreamOutput;

class ExecutorGroupSection extends AbstractSection
{
/**
* @var array
*/
private $groups;

/**
* @var string
*/
private $key;

public function __construct(array $groups, string $key)
{
$this->groups = $groups;
$this->key = $key;
}

public function getSectionName()
{
return sprintf('Execute group with key "%s"', $this->key);
}

public function doAction()
{
$input = new ArrayInput([
'--key' => $this->key,
]);

$output = new ConsoleOutput();
$output->setDecorated(true);

$executeCommand = new ExecuteCommand();
$executeCommand->run($input, $output);

readline('Finished. Press "Enter" to continue');

$this->output->writeln(CommandOutputHelper::clearOutput());
}
}

0 comments on commit 34d553e

Please sign in to comment.