-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add SingleCommandApplication to ease creation of Single Command Application #34819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c985204
to
83ba9b0
Compare
83ba9b0
to
516713a
Compare
src/Symfony/Component/Console/Tests/phpt/single_application/version_default_name.phpt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
src/Symfony/Component/Console/Tests/phpt/single_application/version_name.phpt
Show resolved
Hide resolved
src/Symfony/Component/Console/Tests/phpt/single_application/version_default_name.phpt
Show resolved
Hide resolved
src/Symfony/Component/Console/Tests/phpt/single_application/help_name.phpt
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Console/Tests/phpt/single_application/help_name.phpt
Outdated
Show resolved
Hide resolved
516713a
to
7284543
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7284543
to
0ee2fff
Compare
OK, I updated the PR to add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
It might be worth throwing from methods like setAliases()
which make no sense for such command, but that's for another PR.
Build failures unrelated
This comment has been minimized.
This comment has been minimized.
0ee2fff
to
7855fae
Compare
Failures on appveyor & travis are not related |
70c168e
to
d050196
Compare
…mand Application ``` <?php require __DIR__.'/vendor/autoload.php'; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\SingleCommandApplication; (new SingleCommandApplication()) ->setName('My Super Command') // Optional ->setVersion('1.0.0') // Optional ->setProcessTitle('my_proc_title') // Optional ->addArgument('who', InputArgument::OPTIONAL, 'Who', 'World') // Optional ->setCode(function(InputInterface $input, OutputInterface $output): int { $output->writeln(sprintf('Hello %s!', $input->getArgument('who'))); return 0; }) ->run() ; ```
d050196
to
4af513d
Compare
Thank you @lyrixx. |
…n of Single Command Application (lyrixx) This PR was merged into the 5.1-dev branch. Discussion ---------- [Console] Add SingleCommandApplication to ease creation of Single Command Application | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #34293 | License | MIT | Doc PR | --- ```php <?php require __DIR__.'/vendor/autoload.php'; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\SingleCommandApplication; (new SingleCommandApplication()) ->setName('My Super Command') // Optional ->setVersion('1.0.0') // Optional ->setProcessTitle('my_proc_title') // Optional ->addArgument('who', InputArgument::OPTIONAL, 'Who', 'World') // Optional ->setCode(function(InputInterface $input, OutputInterface $output) { $output->writeln(sprintf('Hello %s!', $input->getArgument('who'))); }) ->run() ; ``` --- Note: I tried this too, and it works as expected: ```php class MyCommand extends SingleCommandApplication { public function execute(InputInterface $input, OutputInterface $output) { $output->writeln('hello'); return 0; } } new MyCommand(); ``` Commits ------- 4af513d [Console] Add SingleCommandApplication to ease creation of Single Command Application
Note: I tried this too, and it works as expected: