Last active
December 12, 2021 01:24
-
-
Save dhrrgn/8847309 to your computer and use it in GitHub Desktop.
Adding global Options/Arguments to Symfony Console Applications
This file contains 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
#!/usr/bin/env php | |
<?php | |
use Symfony\Component\Console\Application; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
require 'vendor/autoload.php'; | |
$app = new Application; | |
// Add global Options to the Application | |
$app->getDefinition()->addOptions([ | |
new InputOption('--env', '-e', InputOption::VALUE_OPTIONAL, 'The environment to operate in.', 'DEV'), | |
]); | |
// You could add global arguments as well | |
$app->getDefinition()->addArguments([ | |
// Arguments Here | |
]); | |
// Add the commands. | |
$app->add(new SomeCommand); | |
// Run it. | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should actually extend the Application class instead