Skip to content

Commit

Permalink
Issue #25: Fix working dir parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Jan 13, 2018
1 parent a6f7be8 commit aa26d3c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
7 changes: 1 addition & 6 deletions src/Commands/BaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ public function getConfigurationFile()
*/
public function initializeRuntimeConfiguration(ConsoleCommandEvent $event)
{
chdir($event->getInput()->getOption('working-dir'));
Robo::loadConfiguration([
'runner.yml.dist',
'runner.yml',
$this->getConfigurationFile(),
], $this->getConfig());
Robo::loadConfiguration([$this->getConfigurationFile()], $this->getConfig());
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ public function getConfigurationFile()
return __DIR__.'/../../config/commands/drupal.yml';
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
*
* @hook init
*/
public function init(InputInterface $input)
{
$this->getComposer()->setWorkingDir($input->getOption('working-dir'));
}

/**
* Command initialization.
*
Expand Down
28 changes: 25 additions & 3 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class TaskRunner
*/
private $application;

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

/**
* TaskRunner constructor.
*
Expand All @@ -66,6 +71,9 @@ public function __construct(InputInterface $input = null, OutputInterface $outpu
$this->input = is_null($input) ? new ArgvInput() : $input;
$this->output = is_null($output) ? new ConsoleOutput() : $output;

$this->workingDir = $this->getWorkingDir($this->input);
chdir($this->workingDir);

$this->config = $this->createConfiguration();
$this->application = $this->createApplication();
$this->container = $this->createContainer($this->input, $this->output, $this->application, $this->config);
Expand Down Expand Up @@ -140,7 +148,11 @@ private function getCommandDiscovery()
*/
private function createConfiguration()
{
return Robo::createConfiguration([__DIR__.'/../config/runner.yml']);
return Robo::createConfiguration([
__DIR__.'/../config/runner.yml',
'runner.yml.dist',
'runner.yml',
]);
}

/**
Expand All @@ -157,7 +169,7 @@ private function createContainer(InputInterface $input, OutputInterface $output,
{
$container = Robo::createDefaultContainer($input, $output, $application, $config);
$container->get('commandFactory')->setIncludeAllPublicMethods(false);
$container->share('task_runner.composer', Composer::class)->withArgument(getcwd());
$container->share('task_runner.composer', Composer::class)->withArgument($this->workingDir);
$container->share('filesystem', Filesystem::class);

// Add service inflectors.
Expand All @@ -179,11 +191,21 @@ private function createApplication()
$application = new Application(self::APPLICATION_NAME, null);
$application
->getDefinition()
->addOption(new InputOption('--working-dir', null, InputOption::VALUE_REQUIRED, 'Working directory, defaults to current working directory.', getcwd()));
->addOption(new InputOption('--working-dir', null, InputOption::VALUE_REQUIRED, 'Working directory, defaults to current working directory.', $this->workingDir));

return $application;
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
*
* @return mixed
*/
private function getWorkingDir(InputInterface $input)
{
return $input->getParameterOption('--working-dir', getcwd());
}

/**
* @param \Robo\Application $application
*/
Expand Down
28 changes: 20 additions & 8 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,45 @@
configuration:
github:
token: "abc"
composer: ''
composer: >
{
"name": "foo/bar"
}
contains:
- "exec('ec-europa/oe-task-runner -t abc')"
- "exec('foo/bar -t abc')"

- command: 'changelog:generate --token def'
configuration:
github:
token: "abc"
composer: ''
composer: >
{
"name": "foo/bar"
}
contains:
- "exec('ec-europa/oe-task-runner -t def')"
- "exec('foo/bar -t def')"

- command: 'changelog:generate --tag 1.2.3'
configuration:
github:
token: "abc"
composer: ''
composer: >
{
"name": "foo/bar"
}
contains:
- "exec('ec-europa/oe-task-runner -t abc --future-release=1.2.3')"
- "exec('foo/bar -t abc --future-release=1.2.3')"

- command: 'changelog:generate --token 123 --tag 1.2.3'
configuration:
github:
token: "abc"
composer: ''
composer: >
{
"name": "foo/bar"
}
contains:
- "exec('ec-europa/oe-task-runner -t 123 --future-release=1.2.3')"
- "exec('foo/bar -t 123 --future-release=1.2.3')"

- command: 'drupal:component-scaffold'
configuration: []
Expand Down

0 comments on commit aa26d3c

Please sign in to comment.