From 8d042a5ab8b38dbadca612bef532bbbe85b9edc9 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Wed, 27 Dec 2023 13:37:45 +0100 Subject: [PATCH] Make backing type a bool, since it defaults anyway on 1 of 2 options. (#971) * Make backing type a bool, since it defaults anyway on 1 of 2 options. * Use --int / -i as flag. --- src/Command/EnumCommand.php | 12 +++++------- tests/TestCase/Command/EnumCommandTest.php | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Command/EnumCommand.php b/src/Command/EnumCommand.php index 8385da49..2118450e 100644 --- a/src/Command/EnumCommand.php +++ b/src/Command/EnumCommand.php @@ -18,7 +18,6 @@ use Cake\Console\Arguments; use Cake\Console\ConsoleOptionParser; -use InvalidArgumentException; /** * Enum code generator. @@ -66,7 +65,7 @@ public function template(): string public function templateData(Arguments $arguments): array { $data = parent::templateData($arguments); - $data['backingType'] = $arguments->getOption('backing-type'); + $data['backingType'] = $arguments->getOption('int') ? 'int' : 'string'; return $data; } @@ -83,11 +82,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar $parser->setDescription( 'Bake backed enums for use in models.' - )->addOption('backing-type', [ - 'help' => 'The return type for the backed enum class', - 'default' => 'string', - 'choices' => ['string', 'int'], - 'short' => 'b', + )->addOption('int', [ + 'help' => 'Using backed enums with int instead of string as return type', + 'boolean' => true, + 'short' => 'i', ]); return $parser; diff --git a/tests/TestCase/Command/EnumCommandTest.php b/tests/TestCase/Command/EnumCommandTest.php index c6d5bc72..678aaf40 100644 --- a/tests/TestCase/Command/EnumCommandTest.php +++ b/tests/TestCase/Command/EnumCommandTest.php @@ -61,7 +61,7 @@ public function testBakeEnum() public function testBakeEnumBackedInt() { $this->generatedFile = APP . 'Model/Enum/FooBar.php'; - $this->exec('bake enum FooBar -b int', ['y']); + $this->exec('bake enum FooBar -i', ['y']); $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertFileExists($this->generatedFile);