Skip to content
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

Support for --if-present when running custom scripts #8304

Closed
christeredvartsen opened this issue Sep 1, 2019 · 4 comments
Closed

Support for --if-present when running custom scripts #8304

christeredvartsen opened this issue Sep 1, 2019 · 4 comments
Labels

Comments

@christeredvartsen
Copy link
Contributor

christeredvartsen commented Sep 1, 2019

It could come in handy to have support for an --if-present flag when running custom scripts using composer run-script, to avoid a non-zero exit code when the script is not defined. This enables running potentially undefined scripts without breaking the execution chain.

My composer.json:

{
  "name": "some/name",
  "license": "MIT"
}

Output of composer diagnose:

Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Composer version: 1.6.3
PHP version: 7.2.19-0ubuntu0.18.04.2
PHP binary path: /usr/bin/php7.2

When I run these command:

composer run-script test
echo $?
composer run-script test --if-present
echo $?

I get the following output:

Script "test" is not defined in this package
1
The "--if-present" option does not exist.
1

And I expected this to happen:

Script "test" is not defined in this package
1
0

If the idea is welcome I'd be happy to implement it and send a pull request to resolve this issue.

@alcohol
Copy link
Member

alcohol commented Sep 2, 2019

I think --if-present is a bit vague / a misnomer. I would sooner call it --ignore-failure or something along those lines. But then the question becomes, is there (or should there be) a difference between a script failing and a script not existing? Also keep in mind that named scripts can reference other scripts, etc.

@alcohol alcohol added the Feature label Sep 2, 2019
@christeredvartsen
Copy link
Contributor Author

I would sooner call it --ignore-failure or something along those lines.

I think this should be a separate feature in that case. --if-present should in my mind only be used for just that, running a script if it is present, and not exit with an error code if the script is not present.

is there (or should there be) a difference between a script failing and a script not existing?

In my opinion this should be two separate cases.

Also keep in mind that named scripts can reference other scripts, etc.

My first thought when using --if-present is it should only refer to the actual script being called, and not scripts that it might refer to.

@Seldaek
Copy link
Member

Seldaek commented Sep 4, 2019

I don't really get the use case for "potentially undefined scripts".. in which context are you running random scripts?

Anyway this sounds like it is about custom automation of some sort.. and I'd argue you can already do it with composer list | grep -q '^ test ' to check for existance of the test script. I don't really see this as warranting a new flag.

@christeredvartsen
Copy link
Contributor Author

OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants