Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[FEATURE] #18 New --format parameter to print data of tables in CSV, …

…XML or JSON (for table helper based commands)
  • Loading branch information...
commit 14540564e9e16f8dbd51b4b0ba4e5565b325272d 1 parent 6378532
@cmuench cmuench authored
Showing with 459 additions and 96 deletions.
  1. +1 −0  changes.txt
  2. BIN  n98-magerun.phar
  3. +25 −22 readme.rst
  4. +8 −2 src/N98/Magento/Command/Admin/User/ListCommand.php
  5. +8 −2 src/N98/Magento/Command/Cache/ListCommand.php
  6. +9 −2 src/N98/Magento/Command/Cache/ReportCommand.php
  7. +17 −8 src/N98/Magento/Command/Config/GetCommand.php
  8. +8 −2 src/N98/Magento/Command/Customer/ListCommand.php
  9. +8 −2 src/N98/Magento/Command/Database/InfoCommand.php
  10. +13 −5 src/N98/Magento/Command/Developer/Module/Dependencies/AbstractCommand.php
  11. +24 −9 src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php
  12. +11 −4 src/N98/Magento/Command/Developer/Module/ListCommand.php
  13. +3 −2 src/N98/Magento/Command/Developer/Module/Observer/ListCommand.php
  14. +14 −4 src/N98/Magento/Command/Developer/Module/Rewrite/ListCommand.php
  15. +13 −5 src/N98/Magento/Command/Developer/Theme/ListCommand.php
  16. +8 −2 src/N98/Magento/Command/Indexer/ListCommand.php
  17. +9 −2 src/N98/Magento/Command/MagentoConnect/ListExtensionsCommand.php
  18. +16 −4 src/N98/Magento/Command/Script/Repository/ListCommand.php
  19. +13 −4 src/N98/Magento/Command/System/Cron/HistoryCommand.php
  20. +14 −4 src/N98/Magento/Command/System/Cron/ListCommand.php
  21. +10 −3 src/N98/Magento/Command/System/Store/Config/BaseUrlListCommand.php
  22. +10 −3 src/N98/Magento/Command/System/Store/ListCommand.php
  23. +13 −4 src/N98/Magento/Command/System/Website/ListCommand.php
  24. +29 −0 src/N98/Util/Console/Helper/Table/Renderer/CsvRenderer.php
  25. +17 −0 src/N98/Util/Console/Helper/Table/Renderer/JsonRenderer.php
  26. +36 −0 src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php
  27. +14 −0 src/N98/Util/Console/Helper/Table/Renderer/RendererInterface.php
  28. +31 −0 src/N98/Util/Console/Helper/Table/Renderer/XmlRenderer.php
  29. +76 −0 src/N98/Util/Console/Helper/TableHelper.php
  30. +1 −1  tests/N98/Magento/Command/Config/GetCommandTest.php
View
1  changes.txt
@@ -6,6 +6,7 @@ RECENT CHANGES
1.85.0
======
+* #18 New --format parameter to print data of tables in CSV, XML or JSON (for table helper based commands)
* #270 script:repo:run and error handling (by Cyrill Schumacher)
* #273 Allow directory as argument for db:dump (by Rick Kuipers)
* #274 Running Setup Resource Scripts Incrementally (by Alan Storm)
View
BIN  n98-magerun.phar
Binary file not shown
View
47 readme.rst
@@ -180,7 +180,7 @@ If search parameter is given the customers are filtered (searchs in firstname, l
.. code-block:: sh
- $ n98-magerun.phar customer:list [search]
+ $ n98-magerun.phar customer:list [--format[="..."]] [search]
Change customer password
""""""""""""""""""""""""
@@ -380,7 +380,7 @@ List Indexes
.. code-block:: sh
- $ n98-magerun.phar index:list
+ $ n98-magerun.phar index:list [--format[="..."]]
Reindex a Index
"""""""""""""""
@@ -473,7 +473,7 @@ Get Config
.. code-block:: sh
- $ n98-magerun.phar config:get [--scope="..."] [--scope-id="..."] [--decrypt] [path]
+ $ n98-magerun.phar config:get [--scope="..."] [--scope-id="..."] [--decrypt] [--format[="..."]] [path]
Arguments:
path The config path
@@ -484,6 +484,7 @@ Options:
--decrypt Decrypt the config value using local.xml's crypt key
--update-script Output as update script lines
--magerun-script Output for usage with config:set
+ --format Output as json, xml or csv
Help:
If path is not set, all available config items will be listed. path may contain wildcards (*)
@@ -555,7 +556,7 @@ List Magento caches
.. code-block:: sh
- $ n98-magerun.phar cache:list
+ $ n98-magerun.phar cache:list [--format[="..."]]
Disable Magento cache
"""""""""""""""""""""
@@ -612,7 +613,7 @@ List admin users
.. code-block:: sh
- $ n98-magerun.phar admin:user:list
+ $ n98-magerun.phar admin:user:list [--format[="..."]]
Create admin user
"""""""""""""""""
@@ -639,7 +640,7 @@ Toggle admin notifications.
$ n98-magerun.phar admin:notifications
Maintenance mode
-"""""""""""""""""""""""
+""""""""""""""""
If no option is provided it toggles the mode on every call.
@@ -648,7 +649,7 @@ If no option is provided it toggles the mode on every call.
$ n98-magerun.phar sys:maintenance [--on] [--off]
Magento system info
-""""""""""""""""""""
+"""""""""""""""""""
Provides info like the edition and version or the configured cache backends.
@@ -663,7 +664,7 @@ Lists all store views.
.. code-block:: sh
- $ n98-magerun.phar sys:store:list
+ $ n98-magerun.phar sys:store:list [--format[="..."]]
Magento Store Config - BaseURLs
"""""""""""""""""""""""""""""""
@@ -672,16 +673,16 @@ Lists base urls for each store.
.. code-block:: sh
- $ n98-magerun.phar sys:store:config:base-url:list
+ $ n98-magerun.phar sys:store:config:base-url:list [--format[="..."]]
Magento Websites
-""""""""""""""
+""""""""""""""""
Lists all websites.
.. code-block:: sh
- $ n98-magerun.phar sys:website:list
+ $ n98-magerun.phar sys:website:list [--format[="..."]]
List Cronjobs
"""""""""""""
@@ -690,7 +691,7 @@ Lists all cronjobs defined in config.xml files.
.. code-block:: sh
- $ n98-magerun.phar sys:cron:list
+ $ n98-magerun.phar sys:cron:list [--format[="..."]]
Run Cronjob
"""""""""""
@@ -711,7 +712,7 @@ Last executed cronjobs with status.
.. code-block:: sh
- $ n98-magerun.phar sys:cron:history
+ $ n98-magerun.phar sys:cron:history [--format[="..."]]
List URLs
"""""""""
@@ -748,7 +749,7 @@ This command is useful if you update your system with enabled maintenance mode.
$ n98-magerun.phar sys:setup:run
Run Setup Scripts Incrementally
-"""""""""""""""""
+"""""""""""""""""""""""""""""""
Runs setup scripts incrementally. (no need to call frontend).
This command runs each new setup script individually in order to increase the transparency of the setup resource system, and reduce the chances of a PHP failure creating an invalid database state.
@@ -980,14 +981,16 @@ Lists all installed modules with codepool and version
.. code-block:: sh
- $ n98-magerun.phar dev:module:list [--codepool[="..."]] [--status[="..."]] [--vendor=[="..."]]
+ $ n98-magerun.phar dev:module:list [--codepool[="..."]] [--status[="..."]] [--vendor=[="..."]] [--format[="..."]]
Rewrite List
""""""""""""
-Lists all registered class rewrites::
+Lists all registered class rewrites.
+
+.. code-blocks:: sh
- $ n98-magerun.phar dev:module:rewrite:list
+ $ n98-magerun.phar dev:module:rewrite:list [--format[="..."]]
Rewrite Conflicts
"""""""""""""""""
@@ -1008,13 +1011,13 @@ Show list of modules which given module depends on
.. code-block:: sh
- $ n98-magerun.phar dev:module:dependencies:on [-a|--all] moduleName
+ $ n98-magerun.phar dev:module:dependencies:on [-a|--all] [--format[="..."]] moduleName
Show list of modules which depend from module
.. code-block:: sh
- $ n98-magerun.phar dev:module:dependencies:from [-a|--all] moduleName
+ $ n98-magerun.phar dev:module:dependencies:from [-a|--all] [--format[="..."]] moduleName
Observer List
"""""""""""""
@@ -1034,7 +1037,7 @@ Lists all frontend themes
.. code-block:: sh
- $ n98-magerun.phar dev:theme:list
+ $ n98-magerun.phar dev:theme:list [--format[="..."]]
Find Duplicates in your theme
@@ -1064,7 +1067,7 @@ List and find connect extensions by a optional search string:
.. code-block:: sh
- $ n98-magerun.phar extension:list <search>
+ $ n98-magerun.phar extension:list [--format[="..."]] <search>
* Requires Magento's `mage` shell script.
* Does not work with Windows as operating system.
@@ -1257,7 +1260,7 @@ The first line of the script can contain a comment (line prefixed with #) which
.. code-block:: sh
- $ n98-magerun.phar script:repo:list
+ $ n98-magerun.phar script:repo:list [--format[="..."]]
If you want to execute a script from repository this can be done by *script:repo:run* command.
View
10 src/N98/Magento/Command/Admin/User/ListCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractAdminUserCommand
{
@@ -14,6 +15,12 @@ protected function configure()
$this
->setName('admin:user:list')
->setDescription('List admin users.')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
}
@@ -38,8 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$this->getHelper('table')
->setHeaders(array('id', 'username', 'email', 'status'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
}
View
10 src/N98/Magento/Command/Cache/ListCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractCacheCommand
{
@@ -14,6 +15,12 @@ protected function configure()
$this
->setName('cache:list')
->setDescription('Lists all magento caches')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
}
@@ -38,8 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getHelper('table')
->setHeaders(array('code', 'status'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
}
View
11 src/N98/Magento/Command/Cache/ReportCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ReportCommand extends AbstractCacheCommand
{
@@ -18,7 +19,13 @@ protected function configure()
->addOption('mtime', 'm', InputOption::VALUE_NONE, 'Output last modification time')
->addOption('filter-id', '', InputOption::VALUE_OPTIONAL, 'Filter output by ID (substring)')
->addOption('filter-tag', '', InputOption::VALUE_OPTIONAL, 'Filter output by TAG (seperate multiple tags by comma)')
- ->addOption('fpc', null, InputOption::VALUE_NONE, 'Use full page cache instead of core cache (Enterprise only!)');
+ ->addOption('fpc', null, InputOption::VALUE_NONE, 'Use full page cache instead of core cache (Enterprise only!)')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
}
@@ -81,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getHelper('table')
->setHeaders($headers)
- ->setRows($table)->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
}
View
25 src/N98/Magento/Command/Config/GetCommand.php
@@ -5,7 +5,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class GetCommand extends AbstractConfigCommand
{
@@ -30,6 +32,12 @@ protected function configure()
->addOption('decrypt', null, InputOption::VALUE_NONE, 'Decrypt the config value using local.xml\'s crypt key')
->addOption('update-script', null, InputOption::VALUE_NONE, 'Output as update script lines')
->addOption('magerun-script', null, InputOption::VALUE_NONE, 'Output for usage with config:set')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
$help = <<<HELP
@@ -39,7 +47,7 @@ protected function configure()
}
/**
- * @param \Symfony\Component\Console\Input\InputInterface $input
+ * @param InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int|void
*/
@@ -106,30 +114,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
} elseif ($input->getOption('magerun-script')) {
$this->renderAsMagerunScript($output, $table);
} else {
- $this->renderAsTable($output, $table);
+ $this->renderAsTable($output, $table, $input->getOption('format'));
}
}
}
/**
* @param OutputInterface $output
- * @param array $table
+ * @param array $table
+ * @param string $format
*/
- protected function renderAsTable(OutputInterface $output, $table)
+ protected function renderAsTable(OutputInterface $output, $table, $format)
{
$formattedTable = array();
foreach ($table as $row) {
$formattedTable[] = array(
$row['path'],
- str_pad($row['scope'], 8, ' ', STR_PAD_BOTH),
- str_pad($row['scope_id'], 8, ' ', STR_PAD_BOTH),
- substr($row['value'], 0, 50)
+ $row['scope'],
+ $row['scope_id'],
+ $row['value'],
);
}
$this->getHelper('table')
->setHeaders(array('Path', 'Scope', 'Scope-ID', 'Value'))
->setRows($formattedTable)
- ->render($output);
+ ->renderByFormat($output, $formattedTable, $format);
}
/**
View
10 src/N98/Magento/Command/Customer/ListCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractCustomerCommand
{
@@ -14,6 +15,12 @@ protected function configure()
$this
->setName('customer:list')
->addArgument('search', InputArgument::OPTIONAL, 'Search query')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
->setDescription('Lists customers')
;
@@ -66,8 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (count($table) > 0) {
$this->getHelper('table')
->setHeaders(array('id', 'email', 'firstname', 'lastname', 'website'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
} else {
$output->writeln('<comment>No customers found</comment>');
}
View
10 src/N98/Magento/Command/Database/InfoCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class InfoCommand extends AbstractDatabaseCommand
{
@@ -16,6 +17,12 @@ protected function configure()
->addArgument('setting', InputArgument::OPTIONAL, 'Only output value of named setting')
->addDeprecatedAlias('database:info', 'Please use db:info')
->setDescription('Dumps database informations')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
$help = <<<HELP
@@ -73,8 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$this->getHelper('table')
->setHeaders(array('Name', 'Value'))
- ->setRows($rows)
- ->render($output);
+ ->renderByFormat($output, $rows, $input->getOption('format'));
}
}
View
18 src/N98/Magento/Command/Developer/Module/Dependencies/AbstractCommand.php
@@ -8,6 +8,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
abstract class AbstractCommand extends AbstractMagentoCommand
{
@@ -37,7 +38,14 @@ protected function configure()
$this->setName(static::COMMAND_NAME)
->addArgument('moduleName', InputArgument::REQUIRED, 'Module to show dependencies')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Show all dependencies (dependencies of dependencies)')
- ->setDescription(static::COMMAND_DESCRIPTION);
+ ->setDescription(static::COMMAND_DESCRIPTION)
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -49,8 +57,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleName = $input->getArgument('moduleName');
$recursive = $input->getOption('all');
- $this->writeSection($output, sprintf(static::COMMAND_SECTION_TITLE_TEXT, $moduleName));
-
+ if ($input->getOption('format') === null) {
+ $this->writeSection($output, sprintf(static::COMMAND_SECTION_TITLE_TEXT, $moduleName));
+ }
$this->detectMagento($output, true);
$this->initMagento();
@@ -60,9 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
usort($dependencies, array($this, 'sortDependencies'));
$this->getHelper('table')
->setHeaders(array('Name', 'Status', 'Current installed version', 'Code pool'))
- ->setRows($dependencies)
->setPadType(STR_PAD_LEFT)
- ->render($output);
+ ->renderByFormat($output, $dependencies, $input->getOption('format'));
} else {
$output->writeln(sprintf(static::COMMAND_NO_RESULTS_TEXT, $moduleName));
}
View
33 src/N98/Magento/Command/Developer/Module/Dependencies/OnCommand.php
@@ -8,6 +8,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class OnCommand extends AbstractMagentoCommand
{
@@ -15,10 +16,18 @@ class OnCommand extends AbstractMagentoCommand
protected function configure()
{
- $this->setName('dev:module:dependencies:on')
- ->addArgument('moduleName', InputArgument::REQUIRED, 'Module to show dependencies')
- ->addOption('all', 'a', InputOption::VALUE_NONE, 'Show all dependencies (dependencies of dependencies)')
- ->setDescription('Show list of modules which given module depends on');
+ $this
+ ->setName('dev:module:dependencies:on')
+ ->addArgument('moduleName', InputArgument::REQUIRED, 'Module to show dependencies')
+ ->addOption('all', 'a', InputOption::VALUE_NONE, 'Show all dependencies (dependencies of dependencies)')
+ ->setDescription('Show list of modules which given module depends on')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -30,7 +39,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleName = $input->getArgument('moduleName');
$recursive = $input->getOption('all');
- $this->writeSection($output, sprintf('List of module %s dependencies', $moduleName));
+
+ if ($input->getOption('format') === null) {
+ $this->writeSection($output, sprintf('List of module %s dependencies', $moduleName));
+ }
$this->detectMagento($output, true);
$this->initMagento();
@@ -39,13 +51,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dependencies = $this->findModuleDependencies($moduleName, $recursive);
if (!empty($dependencies)) {
usort($dependencies, array($this, 'sortDependencies'));
+ } else {
+ $dependencies = array();
+ }
+ if ($input->getOption('format') === null && count($dependencies) === 0) {
+ $output->writeln(sprintf("Module %s doesn't have dependencies", $moduleName));
+ } else {
$this->getHelper('table')
->setHeaders(array('Name', 'Status', 'Current installed version', 'Code pool'))
- ->setRows($dependencies)
->setPadType(STR_PAD_LEFT)
- ->render($output);
- } else {
- $output->writeln(sprintf("Module %s doesn't have dependencies", $moduleName));
+ ->renderByFormat($output, $dependencies, $input->getOption('format'));
}
} catch (\Exception $e) {
$output->writeln($e->getMessage());
View
15 src/N98/Magento/Command/Developer/Module/ListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractMagentoCommand
{
@@ -23,7 +24,14 @@ protected function configure()
->addOption('status', null, InputOption::VALUE_OPTIONAL, 'Show modules with a specific status')
->addOption('vendor', null, InputOption::VALUE_OPTIONAL, 'Show modules of a specified vendor')
->setAliases(array('sys:modules:list')) // deprecated
- ->setDescription('List all installed modules');
+ ->setDescription('List all installed modules')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -40,11 +48,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->findInstalledModules();
$this->filterModules($input);
- if ( ! empty($this->infos)) {
+ if (!empty($this->infos)) {
$this->getHelper('table')
->setHeaders(array('codePool', 'Name', 'Version', 'Status'))
- ->setRows($this->infos)
- ->render($output);
+ ->renderByFormat($output, $this->infos, $input->getOption('format'));
} else {
$output->writeln("No modules match the specified criteria.");
}
View
5 src/N98/Magento/Command/Developer/Module/Observer/ListCommand.php
@@ -20,8 +20,9 @@ protected function configure()
}
/**
- * @param \Symfony\Component\Console\Input\InputInterface $input
- * @param \Symfony\Component\Console\Output\OutputInterface $output
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @throws \InvalidArgumentException
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
View
18 src/N98/Magento/Command/Developer/Module/Rewrite/ListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\TableHelper;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractRewriteCommand
{
@@ -15,6 +16,12 @@ protected function configure()
$this
->setName('dev:module:rewrite:list')
->setDescription('Lists all magento rewrites')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
}
@@ -43,13 +50,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
- if (count($table) > 0) {
+ if (count($table) === 0 && $input->getOption('format') === null) {
+ $output->writeln('<info>No rewrites were found.</info>');
+ } else {
+ if (count($table) == 0) {
+ $table = array();
+ }
$this->getHelper('table')
->setHeaders(array('Type', 'Class', 'Rewrite'))
->setRows($table)
- ->render($output);
- } else {
- $output->writeln('<info>No rewrites were found.</info>');
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
}
View
18 src/N98/Magento/Command/Developer/Theme/ListCommand.php
@@ -4,7 +4,9 @@
use N98\Magento\Command\AbstractMagentoCommand;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractMagentoCommand
{
@@ -12,12 +14,19 @@ protected function configure()
{
$this
->setName('dev:theme:list')
- ->setDescription('Lists all available themes');
+ ->setDescription('Lists all available themes')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
- * @param \Symfony\Component\Console\Input\\Symfony\Component\Console\Input\InputInterface $input
- * @param \Symfony\Component\Console\Output\\Symfony\Component\Console\Output\OutputInterface $output
+ * @param InputInterface $input
+ * @param OutputInterface $output
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
@@ -36,8 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getHelper('table')
->setHeaders(array('Theme'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
10 src/N98/Magento/Command/Indexer/ListCommand.php
@@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractIndexerCommand
{
@@ -14,6 +15,12 @@ protected function configure()
$this
->setName('index:list')
->setDescription('Lists all magento indexes')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
$help = <<<HELP
@@ -42,8 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getHelper('table')
->setHeaders(array('code', 'status', 'time'))
- ->setRows($table)
- ->render($output, $table);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
}
View
11 src/N98/Magento/Command/MagentoConnect/ListExtensionsCommand.php
@@ -5,6 +5,8 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListExtensionsCommand extends AbstractConnectCommand
{
@@ -15,6 +17,12 @@ protected function configure()
->setAliases(array('extension:search'))
->addArgument('search', InputArgument::OPTIONAL, 'Search string')
->setDescription('List magento connection extensions')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
$help = <<<HELP
@@ -54,8 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (count($table) > 0) {
$this->getHelper('table')
->setHeaders(array('Package', 'Version', 'Stability'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
} else {
$output->writeln('<error>' . $extensions . '</error>');
View
20 src/N98/Magento/Command/Script/Repository/ListCommand.php
@@ -6,8 +6,10 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Shell;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractRepositoryCommand
{
@@ -16,6 +18,12 @@ protected function configure()
$this
->setName('script:repo:list')
->setDescription('Lists all scripts in repository')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
;
$help = <<<HELP
@@ -51,12 +59,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$file['description'],
);
}
- $this->getHelper('table')
- ->setHeaders(array('Script', 'Location', 'Description'))
- ->setRows($table)
- ->render($output);
} else {
+ $table = array();
+ }
+
+ if ($input->getOption('format') === null && count($table) === 0) {
$output->writeln('<info>no script file found</info>');
}
+
+ $this->getHelper('table')
+ ->setHeaders(array('Script', 'Location', 'Description'))
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
17 src/N98/Magento/Command/System/Cron/HistoryCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class HistoryCommand extends AbstractMagentoCommand
{
@@ -19,7 +20,14 @@ protected function configure()
{
$this
->setName('sys:cron:history')
- ->setDescription('Last executed cronjobs with status.');
+ ->setDescription('Last executed cronjobs with status.')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -31,7 +39,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
- $this->writeSection($output, 'Last executed jobs');
+ if ($input->getOption('format') === null) {
+ $this->writeSection($output, 'Last executed jobs');
+ }
$this->initMagento();
$collection = \Mage::getModel('cron/schedule')->getCollection();
@@ -49,7 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getHelper('table')
->setHeaders(array('Job', 'Status', 'Finished'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
18 src/N98/Magento/Command/System/Cron/ListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractCronCommand
{
@@ -19,7 +20,14 @@ protected function configure()
{
$this
->setName('sys:cron:list')
- ->setDescription('Lists all cronjobs');
+ ->setDescription('Lists all cronjobs')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -31,13 +39,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
- $this->writeSection($output, 'Cronjob List');
+ if ($input->getOption('format') === null) {
+ $this->writeSection($output, 'Cronjob List');
+ }
+
$this->initMagento();
$table = $this->getJobs();
$this->getHelper('table')
->setHeaders(array_keys(current($table)))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
13 src/N98/Magento/Command/System/Store/Config/BaseUrlListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class BaseUrlListCommand extends AbstractMagentoCommand
{
@@ -14,7 +15,14 @@ protected function configure()
{
$this
->setName('sys:store:config:base-url:list')
- ->setDescription('Lists all base urls');
+ ->setDescription('Lists all base urls')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -41,7 +49,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
ksort($table);
$this->getHelper('table')
->setHeaders(array('id', 'code', 'unsecure_baseurl', 'secure_baseurl'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
13 src/N98/Magento/Command/System/Store/ListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractMagentoCommand
{
@@ -19,7 +20,14 @@ protected function configure()
{
$this
->setName('sys:store:list')
- ->setDescription('Lists all installed store-views');
+ ->setDescription('Lists all installed store-views')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -42,7 +50,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
ksort($table);
$this->getHelper('table')
->setHeaders(array('id', 'code'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
17 src/N98/Magento/Command/System/Website/ListCommand.php
@@ -7,6 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
class ListCommand extends AbstractMagentoCommand
{
@@ -19,7 +20,14 @@ protected function configure()
{
$this
->setName('sys:website:list')
- ->setDescription('Lists all websites');
+ ->setDescription('Lists all websites')
+ ->addOption(
+ 'format',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
+ )
+ ;
}
/**
@@ -31,7 +39,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
- $this->writeSection($output, 'Magento Websites');
+ if ($input->getOption('format') === null) {
+ $this->writeSection($output, 'Magento Websites');
+ }
$this->initMagento();
foreach (\Mage::app()->getWebsites() as $store) {
@@ -44,7 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
ksort($table);
$this->getHelper('table')
->setHeaders(array('id', 'code'))
- ->setRows($table)
- ->render($output);
+ ->renderByFormat($output, $table, $input->getOption('format'));
}
}
View
29 src/N98/Util/Console/Helper/Table/Renderer/CsvRenderer.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace N98\Util\Console\Helper\Table\Renderer;
+
+use Symfony\Component\Console\Output\OutputInterface;
+
+class CsvRenderer implements RendererInterface
+{
+ /**
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
+ * @param array $rows
+ */
+ public function render(OutputInterface $output, array $rows)
+ {
+ if ($output instanceof ConsoleOutput) {
+ $stream = $output->getStream();
+ } else {
+ $stream = fopen('php://stdout', 'w');
+ }
+
+ $i = 0;
+ foreach ($rows as $row) {
+ if ($i++ == 0) {
+ fputcsv($stream, array_keys($row));
+ }
+ fputcsv($stream, $row);
+ }
+ }
+}
View
17 src/N98/Util/Console/Helper/Table/Renderer/JsonRenderer.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace N98\Util\Console\Helper\Table\Renderer;
+
+use Symfony\Component\Console\Output\OutputInterface;
+
+class JsonRenderer implements RendererInterface
+{
+ /**
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
+ * @param array $rows
+ */
+ public function render(OutputInterface $output, array $rows)
+ {
+ $output->writeln(json_encode($rows, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT));
+ }
+}
View
36 src/N98/Util/Console/Helper/Table/Renderer/RendererFactory.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace N98\Util\Console\Helper\Table\Renderer;
+
+class RendererFactory
+{
+ protected static $formats = array(
+ 'csv' => 'N98\Util\Console\Helper\Table\Renderer\CsvRenderer',
+ 'json' => 'N98\Util\Console\Helper\Table\Renderer\JsonRenderer',
+ 'xml' => 'N98\Util\Console\Helper\Table\Renderer\XmlRenderer',
+ );
+
+ /**
+ * @param string $format
+ *
+ * @return bool|RendererInterface
+ */
+ public function create($format)
+ {
+ $format = strtolower($format);
+ if (isset(self::$formats[$format])) {
+ $rendererClass = self::$formats[$format];
+ return new $rendererClass;
+ }
+
+ return false;
+ }
+
+ /**
+ * @return array
+ */
+ public static function getFormats()
+ {
+ return array_keys(self::$formats);
+ }
+}
View
14 src/N98/Util/Console/Helper/Table/Renderer/RendererInterface.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace N98\Util\Console\Helper\Table\Renderer;
+
+use Symfony\Component\Console\Output\OutputInterface;
+
+interface RendererInterface
+{
+ /**
+ * @param OutputInterface $output
+ * @param array $rows
+ */
+ public function render(OutputInterface $output, array $rows);
+}
View
31 src/N98/Util/Console/Helper/Table/Renderer/XmlRenderer.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace N98\Util\Console\Helper\Table\Renderer;
+
+use Symfony\Component\Console\Output\OutputInterface;
+
+class XmlRenderer implements RendererInterface
+{
+ /**
+ * @param \Symfony\Component\Console\Output\OutputInterface $output
+ * @param array $rows
+ */
+ public function render(OutputInterface $output, array $rows)
+ {
+ $dom = new \DOMDocument('1.0', 'UTF-8');
+ $dom->formatOutput = true;
+ $rootXml = $dom->createElement('table');
+ $dom->appendChild($rootXml);
+
+ foreach ($rows as $row) {
+ $rowXml = $dom->createElement('row');
+ foreach ($row as $key => $value) {
+ $key = preg_replace("/[^A-Za-z0-9]/u", '_', $key);
+ $rowXml->appendChild($dom->createElement($key, @iconv('UTF-8', 'UTF-8//IGNORE', $value)));
+ }
+ $rootXml->appendChild($rowXml);
+ }
+
+ $output->writeln($dom->saveXML());
+ }
+}
View
76 src/N98/Util/Console/Helper/TableHelper.php
@@ -2,8 +2,11 @@
namespace N98\Util\Console\Helper;
+use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
+use N98\Util\Console\Helper\Table\Renderer\RendererInterface;
use Symfony\Component\Console\Helper\TableHelper as BaseTableHelper;
use Symfony\Component\Console\Helper\Helper as AbstractHelper;
+use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -16,6 +19,79 @@
class TableHelper extends BaseTableHelper
{
/**
+ * @var string
+ */
+ protected $format;
+
+ /**
+ * @var array
+ */
+ protected $headers = array();
+
+ /**
+ * @param string $format
+ * @return $this
+ */
+ public function setFormat($format)
+ {
+ $this->format = $format;
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFormat()
+ {
+ return $this->format;
+ }
+
+ /**
+ * @param OutputInterface $output
+ */
+ public function render(OutputInterface $output)
+ {
+ if ($this->format == 'csv') {
+ $this->renderCsv();
+ } else {
+ parent::render($output);
+ }
+ }
+
+ /**
+ * @param array $headers
+ * @return $this
+ */
+ public function setHeaders(array $headers)
+ {
+ $this->headers = array_values($headers);
+ parent::setHeaders($headers);
+
+ return $this;
+ }
+
+ /**
+ * @param OutputInterface $outputInterface
+ * @param array $rows
+ * @param string $format
+ */
+ public function renderByFormat(OutputInterface $outputInterface, array $rows, $format = '')
+ {
+ $rendererFactory = new RendererFactory();
+ $renderer = $rendererFactory->create($format);
+ if ($renderer && $renderer instanceof RendererInterface) {
+ foreach ($rows as &$row) {
+ $row = array_combine($this->headers, $row);
+ }
+ $renderer->render($outputInterface, $rows);
+ } else {
+ $this->setRows($rows);
+ $this->render($outputInterface);
+ }
+ }
+
+ /**
* Takes a 2 dimensional tabular array (or iterable object) and outputs an ascii table
*
* @deprecated Use original Symfony table helper
View
2  tests/N98/Magento/Command/Config/GetCommandTest.php
@@ -33,7 +33,7 @@ public function testExecute()
'path' => 'n98_magerun/foo/bar',
)
);
- $this->assertContains('| n98_magerun/foo/bar | default | 0 | 1234 |', $commandTester->getDisplay());
+ $this->assertContains('| n98_magerun/foo/bar | default | 0 | 1234 |', $commandTester->getDisplay());
$commandTester->execute(
array(
Please sign in to comment.
Something went wrong with that request. Please try again.