@@ -44,6 +44,7 @@ final class AddPrefixCommand extends BaseCommand
4444
4545 private $ fileSystem ;
4646 private $ scoper ;
47+ private $ init = false ;
4748
4849 /**
4950 * @inheritdoc
@@ -393,7 +394,9 @@ private function retrieveConfig(InputInterface $input, OutputInterface $output,
393394 if (null === $ configFile ) {
394395 $ configFile = $ this ->makeAbsolutePath (self ::CONFIG_FILE_DEFAULT );
395396
396- if (false === file_exists ($ configFile )) {
397+ if (false === file_exists ($ configFile ) && false === $ this ->init ) {
398+ $ this ->init = true ;
399+
397400 $ initCommand = $ this ->getApplication ()->find ('init ' );
398401
399402 $ initInput = new StringInput ('' );
@@ -409,29 +412,38 @@ private function retrieveConfig(InputInterface $input, OutputInterface $output,
409412 OutputStyle::VERBOSITY_DEBUG
410413 );
411414
412- return Configuration::load (null );
415+ return self ::retrieveConfig ($ input , $ output , $ io );
416+ }
417+
418+ if ($ this ->init ) {
419+ $ configFile = null ;
413420 }
414421 } else {
415422 $ configFile = $ this ->makeAbsolutePath ($ configFile );
416423 }
417424
418- if (false === file_exists ($ configFile )) {
425+ if (null === $ configFile ) {
426+ $ io ->writeln (
427+ 'Loading without configuration file. ' ,
428+ OutputStyle::VERBOSITY_DEBUG
429+ );
430+ } elseif (false === file_exists ($ configFile )) {
419431 throw new RuntimeException (
420432 sprintf (
421- 'Could not find the configuration file "<comment>%s</comment> ". ' ,
433+ 'Could not find the configuration file "%s ". ' ,
422434 $ configFile
423435 )
424436 );
437+ } else {
438+ $ io ->writeln (
439+ sprintf (
440+ 'Using the configuration file "%s". ' ,
441+ $ configFile
442+ ),
443+ OutputStyle::VERBOSITY_DEBUG
444+ );
425445 }
426446
427- $ io ->writeln (
428- sprintf (
429- 'Using the configuration file "<comment>%s</comment>". ' ,
430- $ configFile
431- ),
432- OutputStyle::VERBOSITY_DEBUG
433- );
434-
435447 $ config = Configuration::load ($ configFile );
436448
437449 return $ this ->retrievePaths ($ input , $ config );
0 commit comments