Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a custom command create in composer.json with options?

I'd like to use the Codeception bin file in project A from project B, so in project B's composer.json file I have added this script:

"codecept": "../projectA/vendor/bin/codecept"

With this, I can run a command from project B such as:

composer codecept bootstrap 

However, if I add an option that can be used with the bootstrap command, such as:

composer codecept bootstrap --empty 

Composer throws with the following error:

[Symfony\Component\Console\Exception\RuntimeException]  
The "--empty" option does not exist. 

This is my first time playing around with custom commands, so I'm not sure what I'm missing.

like image 243
grazianodev Avatar asked Oct 24 '25 18:10

grazianodev


2 Answers

Okay, I found it, have to use an extra -- before passing the option, like this:

composer codecept bootstrap -- --empty 
like image 61
grazianodev Avatar answered Oct 27 '25 09:10

grazianodev


The error you see is from Symfony Console that is a dependency of Composer.

The underlying problem is that the command-line argument parser in Symfony Console is flawed (read: limited).

You can work-around that in many cases - but not for all - by using the -- argument delimiter and adding the commands arguments behind. E.g.:

composer codecept bootstrap -- --empty 

However this does only work for command-line options that do not exist in Symfony Console as global arguments. E.g. this won't work for --help, it will show Composers' help text. Or --version, or --quiet and so on and so forth, e.g.:

composer exec codecept-the-foo-baloo bootstrap -- --version
Composer version ...

The command/package must not even be installed. As written this is flawed and introduces such and similar kind of limitation(s).

like image 41
hakre Avatar answered Oct 27 '25 09:10

hakre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!