feat: Allow adding multiple cards with an argument

This commit is contained in:
Dendy 2025-04-11 08:02:20 +02:00
parent 806b70dafd
commit 477f2d3684
1 changed files with 27 additions and 37 deletions

View File

@ -58,10 +58,26 @@ class CreateProductionCommand extends Command
protected function configure(): void
{
//$this
// ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
// ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
//;
$this
->addArgument('count', InputArgument::OPTIONAL, 'Amount of cards to make', 1);
//->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
;
}
protected function createProductionNoteFromTerm(Term $term): void
{
$noteIds = $this->ankiService->findNotesIds(sprintf(
//'VocabKanji:*%s* "note:%s"',
'*%s* "note:%s"',
$term->getKanji(),
SentenceNote::MODEL_NAME,
));
$sNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
$newSlNote = SentenceListeningNote::fromNote($sNote, $term);
if (!$this->ankiService->addNote($newSlNote, 'production')) {
throw new \Exception('Failed to add note!');
}
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -142,7 +158,6 @@ class CreateProductionCommand extends Command
// return strlen($b) <=> strlen($a); // ascending order
//});
printf('Rating terms...');
foreach ($knownTerms as $term) {
$termKanji = self::getOnlyKanji($term->getKanji());
@ -180,11 +195,14 @@ class CreateProductionCommand extends Command
}
printf(" OK\n");
$theChosenTerm = null;
arsort($termCounts);
printf("\n");
$newNotesCount = intval($input->getArgument('count'));
foreach ($termCounts as $term => $count) {
$theChosenTerm = $knownTerms[$term];
if ($newNotesCount <= 0) break;
$termKanji = self::getOnlyKanji($term);
printf("%s: %d\n", $term, $count);
@ -194,23 +212,10 @@ class CreateProductionCommand extends Command
printf(" - %s: %0.2f\n", $iKanji, $knownKanji[$iKanji] / $len);
}
printf("\n");
break;
$this->createProductionNoteFromTerm($knownTerms[$term]);
$newNotesCount -= 1;
};
$noteIds = $this->ankiService->findNotesIds(sprintf(
//'VocabKanji:*%s* "note:%s"',
'*%s* "note:%s"',
$theChosenTerm->getKanji(),
SentenceNote::MODEL_NAME,
));
$theChosenNote = $this->ankiService->getNote($noteIds[array_key_last($noteIds)]);
$newSlNote = SentenceListeningNote::fromNote($theChosenNote, $theChosenTerm);
if (!$this->ankiService->addNote($newSlNote, 'production')) {
throw new \Exception('Failed to add note!');
}
printf(
<<<FMNT
total: %d cards
@ -222,21 +227,6 @@ class CreateProductionCommand extends Command
memory_get_usage() / 1024 / 1024,
);
//dd($kanjiNotes);
//$io = new SymfonyStyle($input, $output);
//$arg1 = $input->getArgument('arg1');
//if ($arg1) {
// $io->note(sprintf('You passed an argument: %s', $arg1));
//}
//if ($input->getOption('option1')) {
// // ...
//}
//$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
return Command::SUCCESS;
}
}