forked from dauxio/daux.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more details on verbose output dauxio#52
- Loading branch information
Showing
11 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
<?php namespace Todaymade\Daux\Console; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Todaymade\Daux\Daux; | ||
|
||
trait RunAction | ||
{ | ||
protected function getLength($content) { | ||
return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content); | ||
} | ||
|
||
protected function runAction($title, OutputInterface $output, $width, \Closure $closure) | ||
protected function runAction($title, $width, \Closure $closure) | ||
{ | ||
$output->write($title); | ||
$verbose = Daux::getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE; | ||
|
||
Daux::write($title, $verbose); | ||
|
||
// 8 is the length of the label + 2 let it breathe | ||
$padding = $width - $this->getLength($title) - 10; | ||
|
||
try { | ||
$response = $closure(function ($content) use ($output, &$padding) { | ||
$response = $closure(function ($content) use (&$padding) { | ||
$padding -= $this->getLength($content); | ||
$output->write($content); | ||
Daux::write($content, $verbose); | ||
}); | ||
} catch (\Exception $e) { | ||
$output->writeln(str_pad(' ', $padding) . '[ <fg=red>FAIL</fg=red> ]'); | ||
$this->status($padding, '[ <fg=red>FAIL</fg=red> ]'); | ||
throw $e; | ||
} | ||
$output->writeln(str_pad(' ', $padding) . '[ <fg=green>OK</fg=green> ]'); | ||
$this->status($padding, '[ <fg=green>OK</fg=green> ]'); | ||
|
||
return $response; | ||
} | ||
|
||
protected function status($padding, $content) | ||
{ | ||
$verbose = Daux::getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE; | ||
$padding = $verbose ? '' : str_pad(' ', $padding); | ||
Daux::writeln($padding . $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters