Skip to content

Commit ff2d3f8

Browse files
authored
Merge pull request #13 from sakuraovq/master
add error handler
2 parents 084afb6 + b4832a7 commit ff2d3f8

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/Command/EntityCommand.php

+18-21
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33

44
namespace Swoft\Devtool\Command;
55

6-
use Leuffen\TextTemplate\TemplateParsingException;
7-
use ReflectionException;
86
use Swoft\Bean\Annotation\Mapping\Inject;
9-
use Swoft\Bean\Exception\ContainerException;
107
use Swoft\Console\Annotation\Mapping\Command;
118
use Swoft\Console\Annotation\Mapping\CommandArgument;
129
use Swoft\Console\Annotation\Mapping\CommandMapping;
1310
use Swoft\Console\Annotation\Mapping\CommandOption;
14-
use Swoft\Db\Exception\DbException;
1511
use Swoft\Db\Pool;
1612
use Swoft\Devtool\Model\Logic\EntityLogic;
13+
use Throwable;
1714
use function input;
1815

1916
/**
@@ -41,16 +38,12 @@ class EntityCommand
4138
* @CommandOption(name="table", desc="database table names", type="string")
4239
* @CommandOption(name="pool", desc="database db pool default is 'db.pool'", type="string")
4340
* @CommandOption(name="path", desc="generate entity file path", type="string", default="@app/Model/Entity")
44-
* @CommandOption(name="y", desc="generating entity file is confirm ", type="string")
41+
* @CommandOption(name="y", desc="do you need confirmation?", type="string")
4542
* @CommandOption(name="field_prefix", desc="database field prefix ,alias is 'fp'", type="string")
46-
* @CommandOption(name="table_prefix", desc="like match database table prefix ,alias is 'tp'", type="string")
47-
* @CommandOption(name="exclude", desc="expect generate database table entity ,alias is 'exc'", type="string")
43+
* @CommandOption(name="table_prefix", desc="like match database table prefix, alias is 'tp'", type="string")
44+
* @CommandOption(name="exclude", desc="expect generate database table entity, alias is 'exc'", type="string")
4845
* @CommandOption(name="td", desc="generate entity template path",type="string", default="@devtool/devtool/resource/template")
4946
*
50-
* @throws TemplateParsingException
51-
* @throws ReflectionException
52-
* @throws ContainerException
53-
* @throws DbException
5447
*/
5548
public function create(): void
5649
{
@@ -63,15 +56,19 @@ public function create(): void
6356
$exclude = input()->getOpt('exc', input()->getOpt('exclude'));
6457
$tplDir = input()->getOpt('td', '@devtool/devtool/resource/template');
6558

66-
$this->logic->create([
67-
(string)$table,
68-
(string)$tablePrefix,
69-
(string)$fieldPrefix,
70-
(string)$exclude,
71-
(string)$pool,
72-
(string)$path,
73-
(bool)$isConfirm,
74-
(string)$tplDir
75-
]);
59+
try{
60+
$this->logic->create([
61+
(string)$table,
62+
(string)$tablePrefix,
63+
(string)$fieldPrefix,
64+
(string)$exclude,
65+
(string)$pool,
66+
(string)$path,
67+
(bool)$isConfirm,
68+
(string)$tplDir
69+
]);
70+
} catch (Throwable $exception) {
71+
output()->colored($exception->getMessage(), 'error');
72+
}
7673
}
7774
}

src/Model/Logic/EntityLogic.php

+6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ class EntityLogic
5555
public function create(array $params): void
5656
{
5757
list($table, $tablePrefix, $fieldPrefix, $exclude, $pool, $path, $isConfirm, $tplDir) = $params;
58+
5859
$tableSchemas = $this->schemaData->getSchemaTableData($pool, $table, $exclude, $tablePrefix);
60+
if (empty($tableSchemas)) {
61+
output()->colored("Generate entity match table is empty!", 'error');
62+
return;
63+
}
64+
5965
foreach ($tableSchemas as $tableSchema) {
6066
$this->readyGenerateId = false;
6167
$this->generateEntity($tableSchema, $pool, $path, $isConfirm, $fieldPrefix, $tplDir);

0 commit comments

Comments
 (0)