22
33namespace Bamarni \Symfony \Console \Autocomplete ;
44
5+ use InvalidArgumentException ;
6+ use RuntimeException ;
57use Symfony \Component \Console \Command \Command ;
68use Symfony \Component \Console \Input \InputInterface ;
79use Symfony \Component \Console \Input \InputArgument ;
@@ -26,13 +28,13 @@ protected function configure()
2628 ;
2729 }
2830
29- protected function execute (InputInterface $ input , OutputInterface $ output )
31+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
3032 {
3133 $ shell = $ input ->getOption ('shell ' );
3234 $ script = $ input ->getArgument ('script ' );
3335
3436 if (!in_array ($ shell , array ('bash ' , 'zsh ' , 'fish ' ))) {
35- throw new \ InvalidArgumentException (sprintf (
37+ throw new InvalidArgumentException (sprintf (
3638 'Completion is only available for Bash, Fish and Zsh, "%s" given. ' ,
3739 $ shell
3840 ));
@@ -66,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6668
6769 $ output ->write ($ this ->render ($ shell . '/default ' , compact ('tools ' )));
6870
69- return ;
71+ return 0 ;
7072 }
7173
7274 /* =====================================
@@ -76,10 +78,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
7678 $ scriptOptions = $ input ->getOption ('script-options ' );
7779
7880 // find all commands
79- $ process = new Process ($ script . ' list ' . $ scriptOptions . ' --format=xml ' );
81+ $ command = $ script . ' list ' . $ scriptOptions . ' --format=xml ' ;
82+ if (method_exists (Process::class, 'fromShellCommandline ' )) {
83+ // Symfony 4+
84+ $ process = Process::fromShellCommandline ($ command );
85+ } else {
86+ // old Symfony way
87+ $ process = new Process ($ command );
88+ }
8089 $ process ->run ();
8190 if (!$ process ->isSuccessful ()) {
82- throw new \ RuntimeException ($ process ->getErrorOutput ());
91+ throw new RuntimeException ($ process ->getErrorOutput ());
8392 }
8493
8594 $ xmlCommands = $ process ->getOutput ();
@@ -133,6 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
133142 'commands_options_descriptions ' => $ commandsOptionsDescriptions ,
134143 'tools ' => $ tools ,
135144 )));
145+
146+ return 0 ;
136147 }
137148
138149 private function render ($ template , $ vars )
0 commit comments