Skip to content

Commit

Permalink
places-setup: redirect non-interactive requests (close #1252)
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <[email protected]>
  • Loading branch information
pulsejet committed Sep 20, 2024
1 parent 85e185d commit ac512fb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Command/PlacesSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class PlacesSetup extends Command
{
protected OutputInterface $output;
protected InputInterface $input;

public function __construct(protected Places $places)
{
Expand All @@ -52,6 +53,8 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output = $output;
$this->input = $input;

$recalculate = (bool) $input->getOption('recalculate');
$force = (bool) $input->getOption('force');

Expand Down Expand Up @@ -104,13 +107,27 @@ protected function warnDownloaded(): bool
$this->output->writeln('');
$this->output->writeln('Are you sure you want to download the planet database?');
$this->output->write('Proceed? [y/N] ');

// Redirect -n users to --force
if (!$this->input->isInteractive()) {
$this->output->writeln(
"\n<error>Non-interactive mode with -n is not supported. ".
'You can use --force instead.</error>',
);

return false;
}

// Read user input
$handle = fopen('php://stdin', 'r');
$line = fgets($handle);
if (false === $line) {
$this->output->writeln('<error>You need an interactive terminal to run this command</error>');

return false;
}

// Check if user wants to proceed
if ('y' !== trim($line)) {
$this->output->writeln('Aborting');

Expand Down

0 comments on commit ac512fb

Please sign in to comment.