Skip to content

Commit 9ab29eb

Browse files
authored
Merge pull request #191 from Deuchnord/ask-before-generate-whole-schema
Ask before adding all Schema.org's vocabulary
2 parents 2938bd2 + e88ab2e commit 9ab29eb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Command/GenerateTypesCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Input\InputInterface;
2525
use Symfony\Component\Console\Logger\ConsoleLogger;
2626
use Symfony\Component\Console\Output\OutputInterface;
27+
use Symfony\Component\Console\Question\ConfirmationQuestion;
2728
use Symfony\Component\Yaml\Parser;
2829
use Twig\Environment;
2930
use Twig\Extension\DebugExtension;
@@ -119,6 +120,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119120
$config = $parser->parse(file_get_contents(self::DEFAULT_CONFIG_FILE));
120121
unset($parser);
121122
} else {
123+
$helper = $this->getHelper('question');
124+
$question = new ConfirmationQuestion('Your project has no config file. The entire Schema.org vocabulary will be built.'.PHP_EOL.'Continue? [yN]', false);
125+
126+
if (!$helper->ask($input, $output, $question)) {
127+
return 0;
128+
}
129+
122130
$config = [];
123131
}
124132

tests/Command/GenerateTypesCommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\SchemaGenerator\Command\GenerateTypesCommand;
1717
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Console\Application;
1819
use Symfony\Component\Console\Tester\CommandTester;
1920
use Symfony\Component\Filesystem\Filesystem;
2021

@@ -436,4 +437,17 @@ public function testSupersededProperties(): void
436437
PHP
437438
, $creativeWork);
438439
}
440+
441+
public function testGenerationWithoutConfigFileQuestion(): void
442+
{
443+
// No config file is given.
444+
$application = new Application();
445+
$application->add(new GenerateTypesCommand());
446+
447+
$command = $application->find('generate-types');
448+
$commandTester = new CommandTester($command);
449+
$commandTester->setInputs(['n']);
450+
self::assertEquals(0, $commandTester->execute([]));
451+
$this->assertRegExp('/The entire Schema\.org vocabulary will be built/', $commandTester->getDisplay());
452+
}
439453
}

0 commit comments

Comments
 (0)