From 82c7a888a0a5140d1381b9855ecf2762eb52659b Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 2 Jul 2024 10:11:49 +0300 Subject: [PATCH] fix: Fix to Create CLI Command --- .../test/cli/SchedulerCommandTest.php | 2 +- .../cli/helpers/CreateCLIClassHelper.php | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php index aeb14d815..605c1bd3f 100644 --- a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php +++ b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php @@ -187,7 +187,7 @@ public function test05() { "Skip"]; $actual = $runner->getOutput(); $idx = 0; - var_dump($actual); + foreach ($expected as $item) { if ($item == 'Skip') { break; diff --git a/webfiori/framework/cli/helpers/CreateCLIClassHelper.php b/webfiori/framework/cli/helpers/CreateCLIClassHelper.php index 9e7ae9e85..72a9caa42 100644 --- a/webfiori/framework/cli/helpers/CreateCLIClassHelper.php +++ b/webfiori/framework/cli/helpers/CreateCLIClassHelper.php @@ -55,18 +55,21 @@ private function getArgs() : array { $addToMore = true; while ($addToMore) { - $argArr = []; - $groupName = $this->getInput('Enter argument name:'); + $argObj = new \webfiori\cli\Argument(); + $argName = $this->getInput('Enter argument name:'); - if (strlen($groupName) > 0) { - $argArr['name'] = $groupName; + if (!$argObj->setName($argName)) { + $this->error('Invalid name provided.'); + continue; } - $argArr['description'] = $this->getInput('Describe this argument and how to use it:', ''); - $argArr['values'] = $this->getFixedValues(); - $argArr['optional'] = $this->confirm('Is this argument optional or not?', true); - $argArr['default'] = $this->getInput('Enter default value:'); + $argObj->setDescription($this->getInput('Describe this argument and how to use it:', '')); + foreach ($this->getFixedValues() as $v) { + $argObj->addAllowedValue($v); + } + $argObj->setIsOptional($this->confirm('Is this argument optional or not?', true)); + $argObj->setDefault($this->getInput('Enter default value:').''); - $argsArr[] = $argArr; + $argsArr[] = $argObj; $addToMore = $this->confirm('Would you like to add more arguments?', false); }