zend-console icon indicating copy to clipboard operation
zend-console copied to clipboard

Mandatory Value Parameters can not be parsed

Open zf2timo opened this issue 9 years ago • 3 comments

I tried to create a route where a group of Value Parameters is mandatory like this example:

<?php
return [
// ....
        'console-export-prepared-products' => [
            'options' => [
                'route' => 'export prepared products (--from-file=|--model=)',
                'defaults' => [
                    'controller' => \Controller\PreparedProductsController::class,
                    'action' => 'export',
                    'verbose' => false,
                ]
            ]
        ],
        //...
  ];

But this results into a InvalidArgumentException:

Fatal error: Uncaught exception 'Zend\Console\Exception\InvalidArgumentException' with message 'Cannot understand Console route at "(--from-file=|--model=)"' in /var/www/mw/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 946 Zend\Console\Exception\InvalidArgumentException: Cannot understand Console route at "(--from-file=|--model=|--recent)" in /var/www/mw/vendor/zendframework/zendframework/library/Zend/Console/RouteMatcher/DefaultRouteMatcher.php on line 432

I expected that the route is only matched if either the parameter --from-file or --model is set.

zf2timo avatar Aug 23 '16 08:08 zf2timo

At this moment zend-console does not support "alternative parameters". You can only use literal alternative:

( foo | bar )

or flag alternative:

( -x | -c )

I can't promise anything, but I'll try to look into this in coming few days.

mtymek avatar Aug 23 '16 23:08 mtymek

As a workaround i use a route definition like this: [--from-file=] [--model=] And in my controller is a validation for the parameters executed.

zf2timo avatar Aug 24 '16 06:08 zf2timo

This repository has been closed and moved to laminas/laminas-console; a new issue has been opened at https://github.com/laminas/laminas-console/issues/2.

weierophinney avatar Dec 31 '19 21:12 weierophinney