console icon indicating copy to clipboard operation
console copied to clipboard

Question about `Fidry\Console\Application\ConfigurableIO` contract

Open llaville opened this issue 1 year ago • 6 comments

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

llaville avatar Mar 11 '23 07:03 llaville

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

llaville avatar Mar 11 '23 08:03 llaville

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

llaville avatar Mar 11 '23 08:03 llaville

I would need to check that use case

theofidry avatar Mar 11 '23 09:03 theofidry

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.

llaville avatar Mar 18 '23 11:03 llaville

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)

theofidry avatar Mar 18 '23 18:03 theofidry

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.

theofidry avatar Sep 24 '23 20:09 theofidry