Skip to content

Commit 64c3b60

Browse files
committed
update AddCommand
remove path as parameter from create method and get it from modle param improve code
1 parent 1f9f789 commit 64c3b60

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/Commands/AddCommand.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __invoke(object $sender, CommandEventArgs $args): void
7676
return;
7777
}
7878

79-
$path = '';
79+
$parameters[$name->getName()] = $name->getValue();
8080
$output = $args->getParameter('--output');
8181
if ($output) {
8282
if (!$output->getValue()) {
@@ -85,23 +85,18 @@ public function __invoke(object $sender, CommandEventArgs $args): void
8585
Console::resetColor();
8686
return;
8787
}
88-
$path = $output->getValue();
89-
$path = trim($path, '/');
88+
$parameters[$output->getName()] = $output->getValue();
9089
}
9190

92-
9391
$templateName = $template->getValue();
9492
$templateName = strtolower($templateName);
9593
$provider = $this->registry->get($templateName);
9694
$generator = $provider->getGenerator();
9795

98-
$parameters[$name->getName()] = $name->getValue();
99-
$parameters['--output'] = $path;
100-
10196
$models = $generator->generate($parameters);
10297

10398
foreach ($models as $model) {
104-
$result = $this->create($model, $path);
99+
$result = $this->create($model);
105100
if (!$result) {
106101
Console::foregroundColor(ConsoleColor::Red);
107102
Console::writeLine("Somthing whent wrong! faild to create {$template}.");
@@ -136,9 +131,9 @@ public function generate(array $parameters): array
136131
return [new CodeModel($name . '.php', $content)];
137132
}
138133

139-
public function create(CodeModel $model, string $basePath): bool
134+
public function create(CodeModel $model): bool
140135
{
141-
$destination = implode('/', [getcwd(), $basePath]);
136+
$destination = implode('/', [getcwd(), $model->getRelativePath()]);
142137

143138
if (!is_dir($destination)) {
144139
mkdir($destination, 0777, true);

0 commit comments

Comments
 (0)