From da1be4be0f2008cf17ae49165e90ae60c0169eb7 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Mon, 30 Nov 2020 15:59:01 +0100 Subject: [PATCH] fix: [command] Generic importer correct usage of options --- src/Command/ImporterCommand.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Command/ImporterCommand.php b/src/Command/ImporterCommand.php index 5c902f8..500e307 100644 --- a/src/Command/ImporterCommand.php +++ b/src/Command/ImporterCommand.php @@ -54,11 +54,17 @@ class ImporterCommand extends Command 'help' => 'The source that should be imported. Can be either a file on the disk or an valid URL.', 'required' => true ]); - $parser->addArgument('primary_key', [ + $parser->addOption('primary_key', [ + 'short' => 'p', 'help' => 'To avoid duplicates, entries having the value specified by the primary key will be updated instead of inserted. Leave empty if only insertion should be done', - 'required' => false, 'default' => null, ]); + $parser->addOption('model_class', [ + 'short' => 'm', + 'help' => 'The target cerebrate model for the import', + 'default' => 'Organisations', + 'choices' => ['Organisations', 'Individuals', 'AuthKeys'] + ]); return $parser; } @@ -67,7 +73,11 @@ class ImporterCommand extends Command $this->io = $io; $configPath = $args->getArgument('config'); $source = $args->getArgument('source'); - $primary_key = $args->getArgument('primary_key'); + $primary_key = $args->getOption('primary_key'); + $model_class = $args->getOption('model_class'); + if (!is_null($model_class)) { + $this->modelClass = $model_class; + } $table = $this->modelClass; $this->loadModel($table);