@@ -38,16 +38,19 @@ protected function configure()
3838 ->setName (self ::NAME )
3939 ->setDescription ('Execute a WP-CLI command ' )
4040 ->addArgument ('wp-command ' , InputArgument::IS_ARRAY , 'The WP-CLI command to execute ' )
41- ->addOption ('environment ' , null , InputOption::VALUE_REQUIRED , 'The environment name ' , 'staging ' );
41+ ->addOption ('environment ' , null , InputOption::VALUE_REQUIRED , 'The environment name ' , 'staging ' )
42+ ->addOption ('async ' , null , InputOption::VALUE_NONE , 'Execute WP-CLI command asynchronously ' );
4243 }
4344
4445 /**
4546 * {@inheritdoc}
4647 */
4748 protected function perform (InputInterface $ input , ConsoleOutput $ output )
4849 {
50+ $ async = $ this ->getBooleanOption ($ input , 'async ' );
4951 $ command = implode (' ' , $ this ->getArrayArgument ($ input , 'wp-command ' ));
5052 $ environment = (string ) $ this ->getStringOption ($ input , 'environment ' );
53+ $ exitCode = 0 ;
5154
5255 if (empty ($ command ) && $ input ->isInteractive ()) {
5356 $ command = $ output ->ask ('Please enter the WP-CLI command to run ' );
@@ -61,15 +64,19 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
6164 throw new RuntimeException (sprintf ('The "wp %s" command isn \'t available remotely ' , $ command ));
6265 }
6366
64- $ output ->info (sprintf ('Running "<comment>wp %s</comment>" on "<comment>%s</comment>" environment ' , $ command , $ environment ));
67+ $ output ->info (sprintf ('Running "<comment>wp %s</comment>" %s "<comment>%s</comment>" environment ' , $ command, $ async ? ' asynchronously on ' : ' on ' , $ environment ));
6568
6669 $ result = $ this ->invokeEnvironmentFunction ($ environment , [
6770 'php ' => sprintf ('bin/wp %s ' , $ command ),
68- ], Arr::get ($ this ->projectConfiguration ->getEnvironment ($ environment ), 'console.timeout ' , 60 ));
71+ ], $ async ? 0 : Arr::get ($ this ->projectConfiguration ->getEnvironment ($ environment ), 'console.timeout ' , 60 ));
6972
70- $ output ->newLine ();
71- $ output ->write ("$ {result['output ' ]}" );
73+ if (!$ async ) {
74+ $ output ->newLine ();
75+ $ output ->write ("$ {result['output ' ]}" );
7276
73- return $ result ['exitCode ' ];
77+ $ exitCode = $ result ['exitCode ' ];
78+ }
79+
80+ return $ exitCode ;
7481 }
7582}
0 commit comments