2424use Symfony \Component \Console \Input \InputInterface ;
2525use Symfony \Component \Console \Input \InputOption ;
2626use Symfony \Component \Console \Output \OutputInterface ;
27+ use Symfony \Component \Process \ExecutableFinder ;
2728use Symfony \Component \Process \Process ;
2829
2930final class ConfigCommand extends Command
@@ -36,7 +37,12 @@ final class ConfigCommand extends Command
3637 /**
3738 * @var string[]
3839 */
39- protected const EDITORS = ['editor ' , 'vim ' , 'vi ' , 'nano ' , 'pico ' , 'ed ' ];
40+ protected const WINDOWS_EDITORS = ['notepad ' ];
41+
42+ /**
43+ * @var string[]
44+ */
45+ protected const UNIX_EDITORS = ['editor ' , 'vim ' , 'vi ' , 'nano ' , 'pico ' , 'ed ' ];
4046
4147 /**
4248 * @var string
@@ -117,28 +123,25 @@ public function handle(): int
117123
118124 break ;
119125 case 'edit ' :
120- if (windows_os ()) {
121- throw new RuntimeException ('The edit config command is not supported on Windows. ' );
122- }
123-
124126 $ editor = value (function () {
125127 if ($ editor = $ this ->option ('editor ' )) {
126128 return $ editor ;
127129 }
128130
129- foreach (self ::EDITORS as $ editor ) {
130- if (exec ("which $ editor " )) {
131+ $ editors = windows_os () ? self ::WINDOWS_EDITORS : self ::UNIX_EDITORS ;
132+ $ executableFinder = new ExecutableFinder ();
133+ foreach ($ editors as $ editor ) {
134+ if ($ executableFinder ->find ($ editor )) {
131135 return $ editor ;
132136 }
133137 }
134138
135- throw new RuntimeException ('No editor found or specified . ' );
139+ throw new RuntimeException ('Unable to find a default editor or specify the editor . ' );
136140 });
137141
138- (new Process ([$ editor , $ file ]))
139- ->setTty (true )
140- ->setTimeout (null )
141- ->mustRun ();
142+ tap (new Process ([$ editor , $ file ]), static function (Process $ process ): void {
143+ windows_os () or $ process ->setTty (true );
144+ })->setTimeout (null )->mustRun ();
142145
143146 break ;
144147 default :
@@ -169,7 +172,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
169172 }
170173
171174 if ($ input ->mustSuggestOptionValuesFor ('editor ' )) {
172- $ suggestions ->suggestValues (self ::EDITORS );
175+ $ suggestions ->suggestValues (self ::UNIX_EDITORS );
173176 }
174177 }
175178
0 commit comments