Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Feb 6, 2019
2 parents 1f0396d + 29a1e09 commit 003ed9f
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 153 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

},
"require-dev": {
"phpunit/phpunit": "7.*"
"phpunit/phpunit": "8.*"
},

"license": "MIT",
Expand Down
88 changes: 46 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Argument/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Gt\Cli\Argument;

abstract class Argument {
const USER_DATA = "__user-data__";
protected $key;
protected $value;

Expand Down
1 change: 1 addition & 0 deletions src/Argument/ArgumentValueList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ArgumentValueList {
protected $valueMap = [];

public function set(string $key, string $value = null):void {
// TODO: Issue #17 can convert existing values to arrays here.
$this->valueMap[$key] = $value;
}

Expand Down
22 changes: 17 additions & 5 deletions src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,28 @@ public function getArgumentValueList(
$argumentValueList = new ArgumentValueList();

foreach($arguments as $argument) {
if($argument instanceof NamedArgument) {
if($argument instanceof CommandArgument) {
continue;
}
elseif($argument instanceof NamedArgument) {
/** @var NamedParameter $parameter */
$parameter = $namedParameterList[
$namedParameterIndex
];

$argumentValueList->set(
$parameter->getOptionName(),
$argument->getValue()
);
if(is_null($parameter)) {
$argumentValueList->set(
Argument::USER_DATA,
$argument->getValue()
);
}
else {
$argumentValueList->set(
$parameter->getOptionName(),
$argument->getValue()
);
}

$namedParameterIndex++;
}
elseif($argument instanceof Argument) {
Expand Down
11 changes: 10 additions & 1 deletion src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(

$this->applicationName = $applicationName;
$this->applicationCommandList = $applicationCommandList;
$this->applicationCommandList []= $this;
}

public function run(ArgumentValueList $arguments = null): void {
Expand All @@ -35,9 +36,17 @@ public function run(ArgumentValueList $arguments = null): void {

$this->writeLine("Available commands:");

$maxNameLength = 0;
foreach($this->applicationCommandList as $command) {
$nameLength = strlen($command->getName());
if($nameLength > $maxNameLength) {
$maxNameLength = $nameLength;
}
}

foreach($this->applicationCommandList as $command) {
$this->writeLine("" .
$command->getName()
str_pad($command->getName(), $maxNameLength, " ")
. "\t"
. $command->getDescription()
);
Expand Down
Loading

0 comments on commit 003ed9f

Please sign in to comment.