-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Env: Fixed run
Argument Passing
#41179
Env: Fixed run
Argument Passing
#41179
Conversation
By enabling the `unknown-options-as-args` parser option, any options passed to the command that are not registered will be given to the command as arguments. This lets us pass them to the container without quoting them. Note: --help and --version can't be passed since they aren't unknown. This is probably fine though and we can handle that using quotes when necessary.
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @ObliviousHarmony! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, very simple way to solve the problem! And quotes still work if the argument matches a wp-env argument as a fallback.
I think we just need to update the README file. For example, we have this notice about needing quotation marks in some cases:
gutenberg/packages/env/README.md
Lines 302 to 312 in c088c44
<div class="callout callout-alert"> | |
To run a WP-CLI command that includes optional arguments, enclose the WP-CLI command in quotation marks; otherwise, the optional arguments are ignored. This is because flags are normally passed to `wp-env` itself, meaning that the flags are not considered part of the argument that specifies the WP-CLI command. With quotation marks, `wp-env` considers everything inside quotation marks the WP-CLI command argument. | |
For example, to list cron schedules with optional arguments that specify the fields returned and the format of the output: | |
```sh | |
wp-env run cli "wp cron schedule list --fields=name --format=csv" | |
``` | |
Without the quotation marks, WP-CLI lists the schedule in its default format, ignoring the `fields` and `format` arguments. | |
</div> |
Edit: oh and we should also note it as an enhancement in the changelog :)
Since we no longer require the quotes, this commit updates the documentation to explain what cases they are required to be used. This will keep it from being a surprise if a command does not behave as expected.
Thanks, @noahtallen, I've added a changelog and updated the documentation. |
Congratulations on your first merged pull request, @ObliviousHarmony! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
What?
As it stands, you need to pass options to
wp-env run
with the entire string having been quoted. This is because ofyargs/yargs
consuming any options even if they aren't defined. This causes problems when trying to encapsulate scripts inpackage.json
files since you can't easily inject more options into the quoted string in the script.Closes #32929.
Why?
This will make it easier to write
wp-env run
commands inpackage.json
scripts that can accept more options. Something likewp-env run tests-wordpress ls -la
will now work without being quoted. With this pull request, you can now pass options.How?
This works by enabling the
unknown-options-as-args
parser option. This results in any unknown options that are given being treated as a positional argument. In the case of a variadic argument like[command...]
, this means we can write commands conveniently.As a note,
--help
and--version
cannot be passed since they are known options. This will also result in other commands failing to execute if unknown flags are passed inappropriately in place of positional arguments.Testing Instructions
npm run wp-env -- run ls -la
-la
option.3.