@@ -199,6 +199,9 @@ public function browse( $_, $assoc_args ) {
199199 * [--insecure]
200200 * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
201201 *
202+ * [--interaction]
203+ * : Control interactive mode. Use `--no-interaction` to disable prompts (interactive by default). Useful for scripting.
204+ *
202205 * ## EXAMPLES
203206 *
204207 * # Install a package hosted at a git URL.
@@ -216,7 +219,12 @@ public function browse( $_, $assoc_args ) {
216219 public function install ( $ args , $ assoc_args ) {
217220 list ( $ package_name ) = $ args ;
218221
219- $ insecure = (bool ) Utils \get_flag_value ( $ assoc_args , 'insecure ' , false );
222+ $ insecure = (bool ) Utils \get_flag_value ( $ assoc_args , 'insecure ' , false );
223+ $ interaction = (bool ) Utils \get_flag_value ( $ assoc_args , 'interaction ' , true );
224+
225+ if ( ! $ interaction ) {
226+ $ this ->set_non_interactive_mode ();
227+ }
220228
221229 $ this ->set_composer_auth_env_var ();
222230 $ git_package = false ;
@@ -639,6 +647,9 @@ public function get( $args, $assoc_args ) {
639647 * [<package-name>...]
640648 * : One or more package names to update. If not specified, all packages will be updated.
641649 *
650+ * [--interaction]
651+ * : Control interactive mode. Use `--no-interaction` to disable prompts (interactive by default). Useful for scripting.
652+ *
642653 * ## EXAMPLES
643654 *
644655 * # Update all packages.
@@ -666,8 +677,17 @@ public function get( $args, $assoc_args ) {
666677 * Generating autoload files
667678 * ---
668679 * Success: Package updated successfully.
680+ *
681+ * @param array<string> $args Positional arguments. One or more package names to update.
682+ * @param array{interaction?: bool} $assoc_args Associative arguments.
669683 */
670- public function update ( $ args = [] ) {
684+ public function update ( $ args , $ assoc_args = [] ) {
685+ $ interaction = (bool ) Utils \get_flag_value ( $ assoc_args , 'interaction ' , true );
686+
687+ if ( ! $ interaction ) {
688+ $ this ->set_non_interactive_mode ();
689+ }
690+
671691 $ this ->set_composer_auth_env_var ();
672692
673693 // Validate package names if provided
@@ -764,6 +784,9 @@ function ( $event ) use ( &$updated_packages ) {
764784 * [--insecure]
765785 * : Retry downloads without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
766786 *
787+ * [--interaction]
788+ * : Control interactive prompts. Use `--no-interaction` to disable interactive questions (useful for scripting).
789+ *
767790 * ## EXAMPLES
768791 *
769792 * # Uninstall package.
@@ -776,7 +799,12 @@ function ( $event ) use ( &$updated_packages ) {
776799 public function uninstall ( $ args , $ assoc_args ) {
777800 list ( $ package_name ) = $ args ;
778801
779- $ insecure = (bool ) Utils \get_flag_value ( $ assoc_args , 'insecure ' , false );
802+ $ insecure = (bool ) Utils \get_flag_value ( $ assoc_args , 'insecure ' , false );
803+ $ interaction = (bool ) Utils \get_flag_value ( $ assoc_args , 'interaction ' , true );
804+
805+ if ( ! $ interaction ) {
806+ $ this ->set_non_interactive_mode ();
807+ }
780808
781809 $ this ->set_composer_auth_env_var ();
782810 $ package = $ this ->get_installed_package_by_name ( $ package_name );
@@ -1722,4 +1750,21 @@ private function get_github_default_branch( $package_name, $insecure = false ) {
17221750
17231751 return $ default_branch ;
17241752 }
1753+
1754+ /**
1755+ * Sets environment variables to enable non-interactive mode.
1756+ *
1757+ * This prevents Git from prompting for credentials (e.g., SSH passwords),
1758+ * which is useful for scripting and automation.
1759+ *
1760+ * Note: This uses putenv() which affects the entire PHP process, including
1761+ * any Git operations spawned by Composer. This is intentional to ensure
1762+ * non-interactive behavior propagates to all child processes.
1763+ */
1764+ private function set_non_interactive_mode () {
1765+ // Prevent Git from prompting for credentials
1766+ putenv ( 'GIT_TERMINAL_PROMPT=0 ' );
1767+ // Prevent SSH from prompting for passwords
1768+ putenv ( 'GIT_SSH_COMMAND=ssh -o BatchMode=yes ' );
1769+ }
17251770}
0 commit comments