Skip to content

Commit

Permalink
Merge pull request #1384 from phalcon/fix/#1383-cli-project-args
Browse files Browse the repository at this point in the history
#1383 - CLI project args
  • Loading branch information
Jeckerson authored Nov 28, 2019
2 parents 986a93d + 0bdc853 commit 8cd4e59
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 27 deletions.
66 changes: 39 additions & 27 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,39 @@ public function parseParameters(array $parameters = [], $possibleAlias = []): ar

$arguments = [];
foreach ($parameters as $parameter => $description) {
if (strpos($parameter, "=") !== false) {
$parameterParts = explode("=", $parameter);
if (count($parameterParts) != 2) {
if (strpos($parameter, '=') !== false) {
$parameterParts = explode('=', $parameter);
if (count($parameterParts) !== 2) {
throw new CommandsException("Invalid definition for the parameter '$parameter'");
}
if (strlen($parameterParts[0]) == "") {

if (strlen($parameterParts[0]) == 0) {
throw new CommandsException("Invalid definition for the parameter '$parameter'");
}

if (!in_array($parameterParts[1], ['s', 'i', 'l'])) {
throw new CommandsException("Incorrect data type on parameter '$parameter'");
}

$this->preparedArguments[$parameterParts[0]] = true;
$arguments[$parameterParts[0]] = [
'have-option' => true,
'option-required' => true,
'data-type' => $parameterParts[1]
'data-type' => $parameterParts[1],
];
} else {
if (!preg_match('/([a-zA-Z0-9]+)/', $parameter)) {
throw new CommandsException("Invalid parameter '$parameter'");
}

$this->preparedArguments[$parameter] = true;
$arguments[$parameter] = [
'have-option' => false,
'option-required' => false
];
continue;
}

if (!preg_match('/([a-zA-Z0-9]+)/', $parameter)) {
throw new CommandsException("Invalid parameter '$parameter'");
}

$this->preparedArguments[$parameter] = true;
$arguments[$parameter] = [
'have-option' => false,
'option-required' => false
];
}

$param = '';
Expand Down Expand Up @@ -267,26 +272,32 @@ public function parseParameters(array $parameters = [], $possibleAlias = []): ar
$param = '';
$paramName = '';
}
if ($arguments[$paramName]['have-option'] == false) {

if (!$arguments[$paramName]['have-option']) {
$receivedParams[$paramName] = true;
} elseif (isset($matches[4])) {
$receivedParams[$paramName] = $matches[4];
}
}
} else {
$param = $argv;
if ($paramName != '') {
if (!empty($arguments[$paramName]['have-option']) && $param == '') {
throw new CommandsException("The parameter '$paramName' requires an option");
}

$receivedParams[$paramName] = $param;
$param = '';
$paramName = '';
} else {
$receivedParams[$i - 1] = $param;
$param = '';
continue;
}

$param = $argv;
if ($paramName != '') {
/**
* @psalm-suppress InvalidArgument
*/
if (!empty($arguments[$paramName]['have-option']) && $param == '') {
throw new CommandsException("The parameter '$paramName' requires an option");
}

$receivedParams[$paramName] = $param;
$param = '';
$paramName = '';
} else {
$receivedParams[$i - 1] = $param;
$param = '';
}
}

Expand All @@ -299,6 +310,7 @@ public function parseParameters(array $parameters = [], $possibleAlias = []): ar
if (!empty($optionsToMerge)) {
$receivedParams = array_merge($optionsToMerge->toArray(), $receivedParams);
}

break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/console/GenerateProjectCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@
$I->seeFileFound(app_path($path3));
$I->seeFileFound(app_path($path3 . '/app/config/config.ini'));
$I->deleteDir(app_path($path3));

/**
* Case 4 - custom template engine
*/
$projectName4 = 'hello_world';
$path4 = $projectsFolder . '/' . $projectName4;

$I->dontSeeFileFound(app_path($path4));
$I->runShellCommand('phalcon project ' . $projectName4 . ' simple --template-engine=volt');
$I->seeFileFound(app_path($path4));
$I->seeFileFound(app_path($path4 . '/app/views/index.volt'));
$I->deleteDir(app_path($path4));

0 comments on commit 8cd4e59

Please sign in to comment.