Skip to content

Commit

Permalink
Generator::checkOverwrite() - Clearer messaging when overwrite skippe…
Browse files Browse the repository at this point in the history
…d (non-forced)
  • Loading branch information
totten committed Sep 17, 2024
1 parent bc2a2a5 commit 9279596
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/CRM/CivixBundle/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,18 @@ public function checkOverwrite($path, $mode): string {
return 'write';
}

if ($mode === 'ask' && !$this->input->isInteractive()) {
$mode = 'if-forced';
}
if ($mode === 'if-forced') {
$mode = $this->input->hasOption('force') && $this->input->getOption('force') ? 'overwrite' : 'keep';
}

if ($mode === 'overwrite' || $mode === TRUE) {
return 'write';
}
if ($mode === 'keep'|| $mode === FALSE) {
$this->io->warning("Skip $file: file already exists");
$this->io->writeln("<error>Skip " . Files::relativize($file) . ": file already exists</error>");
return 'keep';
}
if ($mode === 'abort') {
Expand All @@ -849,12 +856,6 @@ public function checkOverwrite($path, $mode): string {
throw new \RuntimeException("File $relPath already exists. Operation aborted");
}
}
if ($mode === 'ask' || $mode === 'if-forced') {
if ($this->input->hasOption('force') && $this->input->getOption('force')) {
$this->io->note("Overwrite $file in --force mode");
return 'write';
}
}

throw new \RuntimeException("Invalid argument checkOverwrite(...$mode)");
}
Expand Down

0 comments on commit 9279596

Please sign in to comment.