在 CakePHP shell 中,我需要使用不定数量的参数。例如:
cake MyShell mycommand inputFile inputFile2 inputFileN outputFile
就我而言,我确定应该至少有 2 个参数(inputFile
和outputFile
),所以第一个和最后一个,但我不知道中间是否还有其他参数。
所以,在我的getOptionParser()
我有:
$parser->addSubcommand('mycommand', array(
'help' => __('This is my example command'),
'parser' => array(
'arguments' => array(
'inputFile' => array('help' => __('First input file'), 'required' => TRUE),
'outputFile' => array('help' => __('Output file'), 'required' => TRUE)
)
)
));
现在,您可以想象,这仅在我使用两个参数且仅两个参数时才有效。
我知道我无法使用getOptionParser()
和手动检查$this->args
,但我想知道是否有更好的解决方案。
谢谢。