Add --no-interaction flag to prevent Git/SSH prompts in package commands
Add --no-interaction flag to package commands to prevent interactive prompts
- [x] Add
--no-interactionflag towp package installcommand - [x] Add
--no-interactionflag towp package updatecommand - [x] Add
--no-interactionflag towp package uninstallcommand - [x] Set
GIT_TERMINAL_PROMPT=0environment variable when flag is used - [x] Set
GIT_SSH_COMMAND=ssh -o BatchMode=yeswhen flag is used - [x] Update command documentation with new option
- [x] Add tests for the new option
- [x] Document method parameters and putenv() usage
- [x] Change flag to
interactionwith defaulttrue(WP-CLI converts --no-interaction to --interaction=false) - [x] Keep --no-interaction usage in tests
- [x] Fix test to use real package name from package index
Implementation Details
The flag is implemented as interaction with a default value of true:
- Code checks for
interactionflag with defaulttrue - When
interactionisfalse, non-interactive mode is enabled - Tests use
--no-interactionwhich WP-CLI automatically converts to--interaction=false - Documentation uses
[--interaction]syntax
Test Fix
Changed the install test to use wp-cli/restful instead of wp-cli/test-package. The package name must match a real package in the package index, as the code validates against it.
Original prompt
This section details on the original issue you should resolve
<issue_title>Add option to be non-interactive.</issue_title> <issue_description>See https://github.com/wp-cli/package-command/pull/60#pullrequestreview-85985229
Composer supports being run non-interactively so it could be useful to have an option to set this.
In particular it would avoid getting prompted for one's ssh password as can happen depending on one's authorization settings, which is problematic for scripts.</issue_description>
Comments on the Issue (you are @copilot in this section)
@schlessera Yes, agree, we can simply forward such an option. It's an easy addition.
- Fixes wp-cli/package-command#62
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Codecov Report
:x: Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/Package_Command.php | 0.00% | 15 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!
@copilot Change the flag to interaction, but keep usage as no-interaction in tests. WP-CLI has this special feature where it turns --no-interaction into --interaction=false under the hood.
@copilot Change the flag to
interaction, but keep usage asno-interactionin tests. WP-CLI has this special feature where it turns--no-interactioninto--interaction=falseunder the hood.
Changed the flag to interaction with default value true in commit e68d8d6. The code now checks ! $interaction to enable non-interactive mode. Tests continue to use --no-interaction as requested, which WP-CLI automatically converts to --interaction=false.
@copilot After I fixed the synopsis, there is now the following test failures:
001 Scenario: Install a package with --no-interaction flag # features/package-install.feature:1106
When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/test-package --no-interaction` # features/package-install.feature:1130
$ WP_CLI_PACKAGES_DIR=. wp package install wp-cli/test-package --no-interaction
Error: Invalid package: shortened identifier 'wp-cli/test-package' not found.
@copilot After I fixed the synopsis, there is now the following test failures:
...
Fixed in commit 249e76e. Changed the test to use wp-cli/restful instead of wp-cli/test-package. The package name must match a real package in the package index as the code validates against it.