Skip to content

Commit

Permalink
Use ProgressHelper in i18n task.
Browse files Browse the repository at this point in the history
When extracting values indicate the progress when not in verbose mode.
We don't need a progress bar in verbose mode as the shell outputs each
file that is being processed.
  • Loading branch information
markstory committed May 23, 2015
1 parent 3d27a4c commit e738c9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Shell/Helper/ProgressHelper.php
Expand Up @@ -112,8 +112,8 @@ public function increment($num = 1)
public function draw()
{
$numberLen = strlen(' 100%');
$complete = ($this->_progress / $this->_total);
$barLen = floor(($this->_width - $numberLen) * ($this->_progress / $this->_total));
$complete = round($this->_progress / $this->_total, 2);
$barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total);
$bar = '';
if ($barLen > 1) {
$bar = str_repeat('=', $barLen - 1) . '>';
Expand Down
12 changes: 11 additions & 1 deletion src/Shell/Task/ExtractTask.php
Expand Up @@ -349,9 +349,15 @@ public function getOptionParser()
*/
protected function _extractTokens()
{
$progress = $this->_io->helper('progress');
$progress->init(['total' => count($this->_files)]);
$isVerbose = $this->param('verbose');

foreach ($this->_files as $file) {
$this->_file = $file;
$this->out(sprintf('Processing %s...', $file), 1, Shell::VERBOSE);
if ($isVerbose) {
$this->out(sprintf('Processing %s...', $file), 1, Shell::VERBOSE);
}

$code = file_get_contents($file);
$allTokens = token_get_all($code);
Expand All @@ -372,6 +378,10 @@ protected function _extractTokens()
$this->_parse('__dx', ['domain', 'context', 'singular']);
$this->_parse('__dxn', ['domain', 'context', 'singular', 'plural']);

if (!$isVerbose) {
$progress->increment(1);
$progress->draw();
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Shell/Task/ExtractTaskTest.php
Expand Up @@ -37,6 +37,9 @@ public function setUp()
{
parent::setUp();
$this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$progress = $this->getMock('Cake\Shell\Helper\ProgressHelper', [], [$this->io]);
$this->io->method('helper')
->will($this->returnValue($progress));

$this->Task = $this->getMock(
'Cake\Shell\Task\ExtractTask',
Expand Down

0 comments on commit e738c9c

Please sign in to comment.