From 7cd94ba6c9565c3597d18ee1d3ba11b64b3cdb7c Mon Sep 17 00:00:00 2001 From: Doug Green Date: Wed, 25 Jul 2018 13:55:43 -0400 Subject: [PATCH 1/2] Sort the table output. --- src/Command/MetricsCommand.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Command/MetricsCommand.php b/src/Command/MetricsCommand.php index 2b72f75..ce0e0a4 100644 --- a/src/Command/MetricsCommand.php +++ b/src/Command/MetricsCommand.php @@ -151,9 +151,17 @@ protected function outputMetricsJson(OutputInterface $output) * An array containing the table rows. * @param OutputInterface $output * Console output object. + * @param int $sort_column + * The column to sort the output on. */ - protected function outputTable(array $header, array $rows, OutputInterface $output) + protected function outputTable(array $header, array $rows, OutputInterface $output, $sort_column = -1) { + if ($sort_column !== -1) { + uasort($rows, function($a, $b) use ($sort_column) { + return $a[$sort_column] > $b[$sort_column]; + }); + } + $table = new Table($output); $table @@ -182,7 +190,7 @@ protected function outputDatastoresTable(OutputInterface $output) ); } - $this->outputTable($header, $rows, $output); + $this->outputTable($header, $rows, $output, 0); } /** @@ -208,7 +216,7 @@ protected function outputMetricsTable(OutputInterface $output) ); } - $this->outputTable($header, $rows, $output); + $this->outputTable($header, $rows, $output, 0); } /** From c42195b3bc0d7c6b6e7bac6be9dcb43dd9507592 Mon Sep 17 00:00:00 2001 From: Doug Green Date: Wed, 25 Jul 2018 14:00:46 -0400 Subject: [PATCH 2/2] Sort the table output. --- src/Command/MetricsCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Command/MetricsCommand.php b/src/Command/MetricsCommand.php index ce0e0a4..64b0b57 100644 --- a/src/Command/MetricsCommand.php +++ b/src/Command/MetricsCommand.php @@ -151,14 +151,14 @@ protected function outputMetricsJson(OutputInterface $output) * An array containing the table rows. * @param OutputInterface $output * Console output object. - * @param int $sort_column + * @param int $sortColumn * The column to sort the output on. */ - protected function outputTable(array $header, array $rows, OutputInterface $output, $sort_column = -1) + protected function outputTable(array $header, array $rows, OutputInterface $output, $sortColumn = -1) { - if ($sort_column !== -1) { - uasort($rows, function($a, $b) use ($sort_column) { - return $a[$sort_column] > $b[$sort_column]; + if (-1 != $sortColumn) { + uasort($rows, function ($a, $b) use ($sortColumn) { + return $a[$sortColumn] > $b[$sortColumn]; }); }