console
console copied to clipboard
Question about `Fidry\Console\Application\ConfigurableIO` contract
Hello Théo,
Could you give an example how to configure Input Definition at run time with ConfigurableIO
interface ?
With standard Symfony Application, I am able to write something like that, to add a new global application option (only for PHAR distrib)
<?php
protected function configureIO(InputInterface $input, OutputInterface $output)
{
if (Phar::running()) {
$inputDefinition = $this->getDefinition();
$inputDefinition->addOption(
new InputOption(
'manifest',
null,
InputOption::VALUE_NONE,
'Show which versions of dependencies are bundled'
)
);
}
parent::configureIO($input, $output);
}
See real example with overtrue/phplint
v9 at https://github.com/overtrue/phplint/blob/9.0.4/src/Console/Application.php#L61-L75
And also https://github.com/overtrue/phplint/blob/9.0.4/src/Console/Application.php#L50-L59
That allow to display a manifest if available into the metadata
field of the PHAR, by running command like bin/phplint --manifest
I don't know, if it's the best way, but here is my workaround to use a global --manifest
option (dynamically), implemented on BOX manifest application. See https://github.com/llaville/box-manifest/commit/8a95fe5dad2b3bc2844fd7c41e6d7f4797e69e6d
Pros It works as expected : display the manifest only on PHAR distribution
Cons The --manifest
option is not visible when you ask application help, e.g: box-manifest.phar
I would need to check that use case
I'll close this question because I've no more needed to solve this situation. I've refactorised my code back to standard Symfony Console Command that support all features.
I would like to keep this open: I need to review this scenario with Chalsar to review it Symfony itself as well (it works right now but we want to change some things so having this case in mind will be helpful)
Note to self: the current reported use case can be done with getConfiguration()
. One can conditionally add the argument/option there instead of via the configure
hook.
Still need to review this in case there is other use cases.