CakePHP,Shell:如何定义不定数量的参数

CakePHP,Shell:如何定义不定数量的参数,shell,cakephp,cakephp-2.5,Shell,Cakephp,Cakephp 2.5,在CakePHP shell中,我需要使用数量不定的参数。例如: cake MyShell mycommand inputFile inputFile2 inputFileN outputFile 在我的例子中,我确信应该至少有两个参数(inputFile和outputFile),所以第一个和最后一个参数是相同的,但我不知道中间是否还有其他参数 因此,在我的getOptionParser()中,我有: $parser->addSubcommand('mycommand', array(

在CakePHP shell中,我需要使用数量不定的参数。例如:

cake MyShell mycommand inputFile inputFile2 inputFileN outputFile
在我的例子中,我确信应该至少有两个参数(
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
,但我想知道是否有更好的解决方案

谢谢

但我想知道是否有更好的解决办法

其他shell工具允许您通过以下方式指定列表:

cake my --input "file1, file2, file3" --output "out1, out2, out3"
或者,如果您愿意,也可以这样做,但我认为与上面的内容相比,阅读和理解起来并不容易

cake my "file1, file2, file3" "out1, out2, out3"
必须用逗号分解字符串,然后比较两个数组的长度(如果匹配,则显示错误)


在处理每个文件之前,您应该检查它们是否存在,并验证输出位置是否也可写。

谢谢@burzum,这个解决方案可以工作,但我不会使用参数,但是选项(对用户来说更容易)您介意将答案标记为正确吗?非常感谢。