Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Added asking whether a yaml entry should be created in a custom yaml …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
peterjaap committed Nov 27, 2021
1 parent de8f560 commit a3803ce
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Elgentos/Masquerade/Console/IdentifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Illuminate\Database\Capsule\Manager as Capsule;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Yaml\Yaml;

class IdentifyCommand extends Command
{
Expand Down Expand Up @@ -126,6 +128,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
$candidatesTable->setHeaders(['Table', 'Column', 'Suggested formatter', 'Example values']);
$candidatesTable->setRows($candidates);
$candidatesTable->render();

$yamls = [];
foreach ($candidates as $candidate) {
list($table, $column, $formatter, $examples) = $candidate;
$helper = $this->getHelper('question');
$filename = 'src/config/' . $this->platformName . '/' . $table . '.yaml';
if (empty($examples)) {
$examples = 'None';
}
$question = new ConfirmationQuestion(sprintf("<comment>Example values: %s</comment>\nDo you want to add <options=bold>%s</> with formatter <options=bold>%s</> to <options=bold>%s</>?</question> <info>[Y/n]</info> ", print_r($examples, true), $table . '.' . $column, $formatter, $filename), true);

if ($helper->ask($input, $output, $question)) {
$yamls[$filename][$table]['columns'][$column]['formatter'] = $formatter;
}
}

foreach ($yamls as $filename => $content) {
@mkdir(dirname($filename), 0777, true);
file_put_contents($filename, Yaml::dump($content));
$this->output->writeln(sprintf('Wrote instructions to %s', $filename));
}
}

/**
Expand Down

0 comments on commit a3803ce

Please sign in to comment.