8000 Add a way to control which scripts get args and where by Seldaek · Pull Request #12086 · composer/composer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a way to control which scripts get args and where #12086

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

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

Seldaek
Copy link
Member
@Seldaek Seldaek commented Aug 19, 2024

fixes #10734

This is so far fairly experimental/MVP.

Using the example from #10734 (comment) as a base, I got this test case:

{
    "scripts": {
        "command-name": [
            "@composer install --no-dev @no_additional_args",
            "@php runner.php command-name @additional_args",
            "@php runner.php @additional_args command-name"
        ]
    }
}

Then running that script outputs:

 c run command-name -vv -- foo bar
> command-name: @composer install --no-dev
Installing dependencies from lock file
[...]
> command-name: @php runner.php command-name 'foo' 'bar'
> command-name: @php runner.php 'foo' 'bar' command-name

@willrowe
Copy link

I think this would solve the issue nicely. I would expect the additional args to only be forwarded where I denoted it.

In a future version with breaking changes it may be worth revisiting and never forwarding additional args unless explicitly including @additional_args in order to simplify things.

@Seldaek
Copy link
Member Author
Seldaek commented Sep 17, 2024

As you can see the fact that @additional_args were used there suppressed the arg from the other, not sure if that's desirable or not tho as you can also explicitly tag one with @no_additional_args to get rid of them as well..

@naderman any opinion on this? I'd tend towards removing this automatic behavior and making it explicit only.

Also what about naming, any feedback on the tag names?

@naderman
Copy link
Member

I think the magical behavior of not sending args if at least one command in the script requires args explicitly is going to be too confusing. It'll be odd that you remove that one command and suddenly all commands receive args. It's also inconsistent then with how this would work for single command scripts, and I'd rather keep BC here. So I think it's fine to require explicit @no_additional_args rather than magically removing them if something else explicitly asks for them.

@Seldaek Seldaek marked this pull request as ready for review September 18, 2024 09:54
@Seldaek Seldaek merged commit 1793044 into composer:main Sep 18, 2024
20 checks passed
@Seldaek Seldaek deleted the arg_control branch September 18, 2024 12:44
@kaznovac
Copy link
Contributor
kaznovac commented Oct 3, 2024

amazing, thanks @Seldaek

just my two cents - this can be expanded with shell-like syntax for arguments (I find _additional a bit unnecessary)

{
    "scripts": {
        "command-name": [
            "@composer install --no-dev @no_args",
            "@php runner.php command-name @args[1]",
            "@php runner.php @args[1] @args[2] command-name #first two args",
            "@php runner.php @args[*] command-name #all args",
            "@php runner.php @args[0] #the name of the command"
        ]
    }
}

@Seldaek
Copy link
Member Author
Seldaek commented Oct 3, 2024

Yeah we could, but seems a bit overkill tbh.. The main thing I wanted to do was support @no_additional_args to suppress them when you have multiple commands.

And yes the name is verbose and long to ensure there is no clash with anything.

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

Successfully merging this pull request may close these issues.

Feature Request: Add possibility to define which script should get forwarded arguments
4 participants
0