Skip to content

Commit

Permalink
[FEATURE] #18 New --format parameter to print data of tables in CSV, …
Browse files Browse the repository at this point in the history
…XML or JSON (for table helper based commands)
  • Loading branch information
cmuench committed Jan 5, 2014
1 parent 6378532 commit 1454056
Show file tree
Hide file tree
Showing 30 changed files with 459 additions and 96 deletions.
1 change: 1 addition & 0 deletions changes.txt
Expand Up @@ -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)
Expand Down
Binary file modified n98-magerun.phar
Binary file not shown.
47 changes: 25 additions & 22 deletions readme.rst
Expand Up @@ -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
""""""""""""""""""""""""
Expand Down Expand Up @@ -380,7 +380,7 @@ List Indexes
.. code-block:: sh
$ n98-magerun.phar index:list
$ n98-magerun.phar index:list [--format[="..."]]
Reindex a Index
"""""""""""""""
Expand Down Expand Up @@ -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
Expand All @@ -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 (*)
Expand Down Expand Up @@ -555,7 +556,7 @@ List Magento caches
.. code-block:: sh
$ n98-magerun.phar cache:list
$ n98-magerun.phar cache:list [--format[="..."]]
Disable Magento cache
"""""""""""""""""""""
Expand Down Expand Up @@ -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
"""""""""""""""""
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
"""""""""""""""""""""""""""""""
Expand All @@ -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
"""""""""""""
Expand All @@ -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
"""""""""""
Expand All @@ -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
"""""""""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
"""""""""""""""""
Expand All @@ -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
"""""""""""""
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/N98/Magento/Command/Admin/User/ListCommand.php
Expand Up @@ -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
{
Expand All @@ -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()) . ']'
)
;
}

Expand All @@ -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'));
}
}
}
10 changes: 8 additions & 2 deletions src/N98/Magento/Command/Cache/ListCommand.php
Expand Up @@ -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
{
Expand All @@ -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()) . ']'
)
;
}

Expand All @@ -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'));
}
}
}
11 changes: 9 additions & 2 deletions src/N98/Magento/Command/Cache/ReportCommand.php
Expand Up @@ -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
{
Expand All @@ -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()) . ']'
)
;
}

Expand Down Expand Up @@ -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'));
}
}
}
25 changes: 17 additions & 8 deletions src/N98/Magento/Command/Config/GetCommand.php
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/N98/Magento/Command/Customer/ListCommand.php
Expand Up @@ -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
{
Expand All @@ -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')
;

Expand Down Expand Up @@ -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>');
}
Expand Down

0 comments on commit 1454056

Please sign in to comment.