Skip to content

Commit

Permalink
Allow --exclude to specify an exclusive list of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Aug 19, 2015
1 parent 5219cf1 commit e811853
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
10 changes: 10 additions & 0 deletions src/Commands/Module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected function configure() {
'Optional list of modules to filter (separate by space)'
);
$this->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Module directory');
$this->addOption('exclude', 'e', InputOption::VALUE_NONE, "Makes list of modules exclusive instead of inclusive");
}

/**
Expand All @@ -44,4 +45,13 @@ protected function getInputDirectory() {
protected function getInputModules() {
return $this->input->getArgument('modules') ?: array();
}

/**
* Check if this list is exclusive. Default to inclusive if not specified
*
* @return bool
*/
protected function getInputExclude() {
return $this->input->getOption('exclude');
}
}
3 changes: 2 additions & 1 deletion src/Commands/Module/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class Translate extends Module {
protected function fire() {
$directory = $this->getInputDirectory();
$modules = $this->getInputModules();
$listIsExclusive = $this->getInputExclude();

$translate = new UpdateTranslations($this, $directory, $modules);
$translate = new UpdateTranslations($this, $directory, $modules, $listIsExclusive);
$translate->run($this->input, $this->output);
//$step->run($this->input, $this->output);
}
Expand Down
39 changes: 24 additions & 15 deletions src/Steps/Release/UpdateTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,33 @@ class UpdateTranslations extends Step {
protected $project;

/**
* List of module names to translate. 'installer' specifies the core project
*
* @var array
*/
protected $modules;

/**
* If true, then $modules is the list of modules that should NOT be translated
* rather than translated.
*
* @var bool
*/
protected $listIsExclusive;

/**
* Create a new translation step
*
* @param Command $command
* @param string $directory Where to translate
* @param array $modules Optional list of modules to limit translation to
* @param bool $listIsExclusive If this list is exclusive. If false, this is inclusive
*/
public function __construct(Command $command, $directory, $modules = array()) {
public function __construct(Command $command, $directory, $modules = array(), $listIsExclusive = false) {
parent::__construct($command);

$this->modules = $modules;
$this->listIsExclusive = $listIsExclusive;
$this->project = new Project($directory);
}

Expand All @@ -74,20 +85,12 @@ public function getProject() {
return $this->project;
}

/**
*
* @return array
*/
public function getModules() {
return $this->modules;
}

public function getStepName() {
return 'translations';
}

public function run(InputInterface $input, OutputInterface $output) {
$modules = $this->getModuleItems($output);
$modules = $this->getModules($output);
$this->log($output, sprintf("Updating translations for %d module(s)", count($modules)));
$this->checkVersion($output);
$this->pullSource($output, $modules);
Expand Down Expand Up @@ -286,24 +289,30 @@ public function commitChanges(OutputInterface $output, $modules) {
* @param OutputInterface
* @return Module[]
*/
protected function getModuleItems(OutputInterface $output) {
protected function getModules(OutputInterface $output) {
$modules = $this->getProject()->getModules();
$filter = $this->getModules();
$filter = $this->modules;
$listIsExclusive = $this->listIsExclusive;

// Get only modules with translations
$self = $this;
return array_filter($modules, function($module) use ($output, $filter, $self) {
return array_filter($modules, function($module) use ($output, $filter, $listIsExclusive, $self) {
// Automatically skip un-translateable modules
if(empty($filter)) {
return $module->isTranslatable();
}

// Skip filtered
// If unspecified, include this if the list is exclusive only (and valid)
if(!in_array($module->getName(), $filter)) {
return $listIsExclusive && $module->isTranslatable();
}

// Skip matching modules if list is exclusive
if($listIsExclusive) {
return false;
}

// Warn if this module has no translations
// Warn if this module was explicitly selected, but has no translations
if(!$module->isTranslatable()) {
$self->log(
$output,
Expand Down

0 comments on commit e811853

Please sign in to comment.