Commit f269fb82 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

change the import method

parent b491604e
......@@ -39,7 +39,7 @@ copy `lexicon.tsv` and `spec.txt` in a new folder in `application/data/lexicons`
(some ready to use scripts are available in the `script/` folder.)
```
sudo docker-compose exec apache bash
console lexicon:import FOLDERNAME
console lexicon:import
```
Grid generation
......
......@@ -3,10 +3,12 @@
namespace LexiconBundle\Command;
use LexiconBundle\Manager\ImportManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Finder\Finder;
class ImportLexiconCommand extends ContainerAwareCommand
{
......@@ -14,20 +16,29 @@ class ImportLexiconCommand extends ContainerAwareCommand
{
$this
->setName('lexicon:import')
->setDescription('Put your files, named exactly "lexicon.tsv" & "spec.txt" in a directory (ex:/euskara) in application/data/lexicons')
->addArgument('directory', InputArgument::REQUIRED, 'name of directory in application/data/lexicons');
->setDescription('Put your files, named exactly "lexicon.tsv" & "spec.txt" in a directory (ex:/euskara) in application/data/lexicons');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$pathLexiconDir = $input->getArgument('directory');
$output->writeln('Available directories in <comment>./data/lexicons/</comment>');
$finder = new Finder();
$dirs = $finder->directories()->in('./data/lexicons')->depth('== 0');
$directories = [];
foreach ($dirs as $dir) {
$name = basename($dir);
$directories[] = $name;
$output->writeln('* <comment>'.$name.'</comment>');
}
$helper = $this->getHelper('question');
$dirName = new Question("Please enter the directory name \n");
$pathLexiconDir = $helper->ask($input, $output, $dirName);
if ($pathLexiconDir) {
if (in_array($pathLexiconDir, $directories)) {
echo 'You passed an argument: ' . $pathLexiconDir . "\n\n";
$importManager = $this->getContainer()->get('lexicon_manager.import');
$importManager->importLexicon($pathLexiconDir);
} else {
echo 'Argument missing';
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment