Created
January 5, 2011 21:06
-
-
Save wilmoore/767014 to your computer and use it in GitHub Desktop.
Symfony Console -- injecting additional top-level options/arguments at the program level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* php job-queue.php --environment=local [command|namespace:command] | |
* php job-queue.php --environment=local job:monitor | |
* | |
* NOTE: | |
* looks like you can actually put the option anywhere...the folllowing works just fine | |
* > php job-queue.php job:monitor --environment=local | |
*/ | |
// inject custom required argument (execution halts if program is called without this argument) | |
$this->definition->addArguments(array( | |
new InputArgument('environment', InputArgument::REQUIRED, 'application environment'), | |
)); | |
// inject custom required option (option actually seems to be optional even though it is defined as required) | |
// From a command, you can now do: | |
// $input->getOption('environment') | |
$this->definition->addOptions(array( | |
new InputOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'application environment'), | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment