mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 11:36:23 +00:00
1.1 KiB
1.1 KiB
id | title |
---|---|
1b9bdd03-0b2c-4ed1-8bf5-fe9169b434b3 | Single Command Applications |
Syntax
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
(new SingleCommandApplication())
->setCode(function (InputInterface $input, OutputInterface $output) {
// add here the code of your console command...
})
->run();
// ...
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\SingleCommandApplication;
(new SingleCommandApplication())
->setName('My Super Command')
->setVersion('1.0.0')
->setHelp('This command allows you to...')
->addArgument('foo', InputArgument::OPTIONAL, 'The directory')
->addOption('bar', null, InputOption::VALUE_REQUIRED)
->setCode(function (InputInterface $input, OutputInterface $output) {
// ...
})
->run();