Skip to content

Commit 61b862e

Browse files
authored
Fix AddPrefix & Init commands (#185)
1 parent d65fca7 commit 61b862e

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/Console/Command/AddPrefixCommand.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/Console/Command/InitCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8282

8383
$configFile = $this->retrieveConfig($input, $io);
8484

85+
if (null === $configFile) {
86+
$io->writeln('Skipping configuration file generator.');
87+
88+
return 0;
89+
}
90+
8591
$this->fileSystem->copy(self::CONFIG_FILE_TEMPLATE, $configFile);
8692

8793
$io->writeln([

tests/Console/Command/AddPrefixCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ public function test_throws_an_error_when_passing_a_non_existent_config()
798798
} catch (RuntimeException $exception) {
799799
$this->assertSame(
800800
sprintf(
801-
'Could not find the configuration file "<comment>%sunknown</comment>".',
801+
'Could not find the configuration file "%sunknown".',
802802
$this->tmp.DIRECTORY_SEPARATOR
803803
),
804804
$exception->getMessage()

0 commit comments

Comments
 (0)