2
2
3
3
namespace Bamarni \Symfony \Console \Autocomplete ;
4
4
5
+ use InvalidArgumentException ;
6
+ use RuntimeException ;
5
7
use Symfony \Component \Console \Command \Command ;
6
8
use Symfony \Component \Console \Input \InputInterface ;
7
9
use Symfony \Component \Console \Input \InputArgument ;
@@ -26,13 +28,13 @@ protected function configure()
26
28
;
27
29
}
28
30
29
- protected function execute (InputInterface $ input , OutputInterface $ output )
31
+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
30
32
{
31
33
$ shell = $ input ->getOption ('shell ' );
32
34
$ script = $ input ->getArgument ('script ' );
33
35
34
36
if (!in_array ($ shell , array ('bash ' , 'zsh ' , 'fish ' ))) {
35
- throw new \ InvalidArgumentException (sprintf (
37
+ throw new InvalidArgumentException (sprintf (
36
38
'Completion is only available for Bash, Fish and Zsh, "%s" given. ' ,
37
39
$ shell
38
40
));
@@ -66,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
66
68
67
69
$ output ->write ($ this ->render ($ shell . '/default ' , compact ('tools ' )));
68
70
69
- return ;
71
+ return 0 ;
70
72
}
71
73
72
74
/* =====================================
@@ -76,10 +78,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
76
78
$ scriptOptions = $ input ->getOption ('script-options ' );
77
79
78
80
// 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
+ }
80
89
$ process ->run ();
81
90
if (!$ process ->isSuccessful ()) {
82
- throw new \ RuntimeException ($ process ->getErrorOutput ());
91
+ throw new RuntimeException ($ process ->getErrorOutput ());
83
92
}
84
93
85
94
$ xmlCommands = $ process ->getOutput ();
@@ -133,6 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
133
142
'commands_options_descriptions ' => $ commandsOptionsDescriptions ,
134
143
'tools ' => $ tools ,
135
144
)));
145
+
146
+ return 0 ;
136
147
}
137
148
138
149
private function render ($ template , $ vars )
0 commit comments