Skip to content

Commit

Permalink
Change style when dump dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Thinardon committed Jan 4, 2018
1 parent e866416 commit 1e7bbde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Improve the format when call dump command

## [2.1.0] - 2017-12-22
### Added
Expand Down
27 changes: 15 additions & 12 deletions src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->newLine();

// Read dictionaries information
$tableRows = $this->getDictionariesDetail($dictionaryName);
if (\is_null($dictionaryName)) {
$dictionaries = $this->registry->all();
} else {
$dictionaries = [$this->registry->get($dictionaryName)];
}

$tableRows = $this->getDictionariesDetail($dictionaries);

// Output data
if (\sizeof($tableRows) > 0) {
$io->table([], $tableRows);
foreach ($tableRows as $header => $raws) {
$io->table([$header], $raws);
}
} elseif (!\is_null($dictionaryName) && 0 === \sizeof($tableRows)) {
$errorIo->error("No dictionary named $dictionaryName");
}
}

/**
* Get all dictionaries with they values
* If $dictionaryName is set, only display dictionary matching dictionary
*
* @param null|string $dictionaryName the dictionary name asked for filtering
* @param array $dictionaries
* @return array rows to display
*/
private function getDictionariesDetail($dictionaryName = null)
private function getDictionariesDetail(array $dictionaries = [])
{
$tableRows = [];
/** @var Dictionary $dico */
foreach ($this->registry->all() as $dico) {
if (!\is_null($dictionaryName) && $dictionaryName === $dico->getName() || \is_null($dictionaryName)) {
$tableRows[] = ["<fg=cyan>{$dico->getName()}</fg=cyan>"];
foreach ($dico as $key => $value) {
$tableRows[] = [" $key\t| $value"];
}
foreach ($dictionaries as $dico) {
foreach ($dico as $key => $value) {
$tableRows["<fg=cyan>{$dico->getName()}</fg=cyan>"][] = [$key, $value];
}
}

Expand Down

0 comments on commit 1e7bbde

Please sign in to comment.