I can't seem to find a simple concrete example of how to receive an argument on a CakePHP 2 shell script.
class TestShell extends AppShell {
public function argumentTest(){
$parser = parent::getOptionParser();
$parser->addArgument('testArgument', array('short' => 't','help' => 'The test argument'));
var_dump($this->params);
}
}
I then try and call it:
Console/cake TestShell argumentTest --t 45
Console/cake TestShell argumentTest -t 45
Console/cake TestShell argumentTest --testArgument 45
Console/cake TestShell argumentTest -testArgument 45
with all of the above I get this as a response:
Usage:
cake lot_web_service [-h] [-v] [-q]
What am I doing wrong?
You should set up the arguments when the option parser is set up:
public function getOptionParser() {
$parser = parent::getOptionParser();
//configure parser
return $parser;
}
This ensures that the options and arguments are set up prior to dispatching the call. Also, from what it looks like, you're wanting addOption() instead of addArgument().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With