package-command icon indicating copy to clipboard operation
package-command copied to clipboard

Add --no-interaction flag to prevent Git/SSH prompts in package commands

Open Copilot opened this issue 2 months ago • 5 comments

Add --no-interaction flag to package commands to prevent interactive prompts

  • [x] Add --no-interaction flag to wp package install command
  • [x] Add --no-interaction flag to wp package update command
  • [x] Add --no-interaction flag to wp package uninstall command
  • [x] Set GIT_TERMINAL_PROMPT=0 environment variable when flag is used
  • [x] Set GIT_SSH_COMMAND=ssh -o BatchMode=yes when 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 interaction with default true (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 interaction flag with default true
  • When interaction is false, non-interactive mode is enabled
  • Tests use --no-interaction which 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.

Copilot avatar Nov 02 '25 15:11 Copilot

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!

codecov[bot] avatar Nov 02 '25 15:11 codecov[bot]

@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.

swissspidy avatar Nov 02 '25 16:11 swissspidy

@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.

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 avatar Nov 02 '25 16:11 Copilot

@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.

swissspidy avatar Nov 02 '25 16:11 swissspidy

@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.

Copilot avatar Nov 02 '25 16:11 Copilot