From 477f2d368498a9c2a23ece36bc1c71be383ffeb7 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Fri, 11 Apr 2025 08:02:20 +0200 Subject: [PATCH] feat: Allow adding multiple cards with an argument --- src/Command/CreateProductionCommand.php | 64 +++++++++++-------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/src/Command/CreateProductionCommand.php b/src/Command/CreateProductionCommand.php index 4f6fbc4..905bb85 100644 --- a/src/Command/CreateProductionCommand.php +++ b/src/Command/CreateProductionCommand.php @@ -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( <<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; } }