Last active
          August 29, 2015 14:03 
        
      - 
      
- 
        Save ngyuki/fadaefec09f5bd05d280 to your computer and use it in GitHub Desktop. 
    symfony console single
  
        
  
    
      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 | |
| require __DIR__ . '/vendor/autoload.php'; | |
| use Symfony\Component\Console\Application; | |
| use Symfony\Component\Console\Command\Command; | |
| use Symfony\Component\Console\Input\InputOption; | |
| use Symfony\Component\Console\Input\InputInterface; | |
| use Symfony\Component\Console\Output\OutputInterface; | |
| class MyApplication extends Application | |
| { | |
| private function getCalleeName() | |
| { | |
| global $argv; | |
| return basename($argv[0]); | |
| } | |
| protected function getCommandName(InputInterface $input) | |
| { | |
| return $this->getCalleeName(); | |
| } | |
| protected function getDefaultCommands() | |
| { | |
| $commands = parent::getDefaultCommands(); | |
| $commands[] = (new Command($this->getCalleeName())) | |
| ->setDescription("Hello") | |
| ->addOption("name", "N", InputOption::VALUE_OPTIONAL, "Name", "unknown") | |
| ->setCode(function (InputInterface $input, OutputInterface $output) { | |
| $name = $input->getOption('name'); | |
| $output->writeln("Hello <info>$name</info>"); | |
| }) | |
| ; | |
| return $commands; | |
| } | |
| public function getDefinition() | |
| { | |
| $definition = parent::getDefinition(); | |
| $definition->setArguments(); | |
| return $definition; | |
| } | |
| } | |
| (new MyApplication())->run(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment