Skip to content

Commit 7f7dd2a

Browse files
committed
Changed behaviour due to camelCase properties
1 parent ff0f265 commit 7f7dd2a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

examples/application.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
->addPositional(Type::string(), 'name', 'Name for migration.')
2121
->addOptional(Type::file(false), 'template', help: 'File with template of migration.', default: './migration.tpl');
2222

23+
$commander->addCommand('init', new Init(), 'Initialization of Migration DB.');
2324
$commander->run();
2425

2526

2627
function migrate(DynamicResult $result, IO $io): void
2728
{
2829
$io->writeLn('Running some migrations.');
29-
$result->{'dry-run'} && $io->writeLn('Launch simulation only.');
30+
$result->dryRun && $io->writeLn('Launch simulation only.');
3031

3132
sleep(2);
3233

@@ -48,3 +49,13 @@ function create(DynamicResult $result, IO $io): void
4849
$io->writeLn("Migration {$result->name} will be created in {$dir}.");
4950
$io->exitSuccess();
5051
}
52+
53+
class Init
54+
{
55+
public function __invoke(DynamicResult $result, IO $io): void
56+
{
57+
$configType = $io->makeSelection('Select type of config file.', ['php', 'json', 'neon']);
58+
$create = $io->makeConfirmation("Do you really want create a config.{$configType} file?");
59+
$io->writeLn($create ? 'File created.' : 'Bye bye.');
60+
}
61+
}

src/Command.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Lawondyss\ParexCommander\Exception\ParexCommanderException;
1212

1313
use function implode;
14+
use function lcfirst;
15+
use function str_replace;
16+
use function ucwords;
1417

1518
use const PHP_EOL;
1619

@@ -97,7 +100,7 @@ public function run(Parex $parex, IO $io): never
97100
$casted = [];
98101

99102
foreach ($this->synopses as $synopsis) {
100-
$name = $synopsis->name;
103+
$name = $this->camelCase($synopsis->name);
101104
$value = $synopsis->isPositional()
102105
? ($values->POSITIONAL[$synopsis->position] ?? null)
103106
: $values->{$name};
@@ -204,4 +207,10 @@ protected function checkPositional(DynamicResult $result): void
204207
}
205208
}
206209
}
210+
211+
212+
protected function camelCase(string $s): string
213+
{
214+
return lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $s))));
215+
}
207216
}

src/ParexCommander.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929

3030
public function addCommand(string $name, callable $handler, string $description = '', ?string $version = null): Command
3131
{
32-
return $this->commands[$name] = new Command($name, $handler, $description, $version);
32+
return $this->commands[$name] = new Command($name, $handler(...), $description, $version);
3333
}
3434

3535

0 commit comments

Comments
 (0)