Skip to content

Commit 13742e8

Browse files
author
Robin de Graaf
committed
0.3.0 - cleanup, renames, more tests
1 parent bd9ed5e commit 13742e8

19 files changed

Lines changed: 374 additions & 173 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Parable Console
22

3+
## 0.3.0
4+
5+
_Changes_
6+
7+
- Renamed `Option` and `Argument` to have `Parameter` suffix for clarity (`OptionParameter` and `ArgumentParameter`).
8+
- Renamed `Help` command to `HelpCommand` for clarity.
9+
- Renamed `Command` and `Parameter` namespaces to plural for consistency.
10+
- Changed `Environment::TERMINAL_DEFAULT_HEIGHT` to 24.
11+
- Added `InputTest` to prevent future breaking changes to that class as well.
12+
313
## 0.2.0
414

515
_Changes_

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515
"require": {
1616
"php": ">=7.1",
17-
"parable-php/di": "^0.2.3"
17+
"parable-php/di": "^0.2.5"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "^7.0"

src/Application.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Parable\Console;
44

5+
use Throwable;
6+
57
class Application
68
{
79
/**
@@ -53,13 +55,16 @@ public function __construct(
5355
$this->input = $input;
5456
$this->parameter = $parameter;
5557

56-
set_exception_handler(function (Exception $e) {
58+
$throwableClosure = function (Throwable $e) {
5759
$this->output->writeErrorBlock([$e->getMessage()]);
5860

5961
if ($this->activeCommand) {
6062
$this->output->writeln('<yellow>Usage</yellow>: ' . $this->activeCommand->getUsage());
6163
}
62-
});
64+
};
65+
66+
set_exception_handler($throwableClosure);
67+
set_error_handler($throwableClosure);
6368
}
6469

6570
public function setName(string $name): void

src/Command.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Parable\Console;
44

5-
use Parable\Console\Parameter\Argument;
6-
use Parable\Console\Parameter\Option;
5+
use Parable\Console\Parameters\ArgumentParameter;
6+
use Parable\Console\Parameters\OptionParameter;
77

88
class Command
99
{
@@ -43,12 +43,12 @@ class Command
4343
protected $callable;
4444

4545
/**
46-
* @var Option[]
46+
* @var OptionParameter[]
4747
*/
4848
protected $options = [];
4949

5050
/**
51-
* @var Argument[]
51+
* @var ArgumentParameter[]
5252
*/
5353
protected $arguments = [];
5454

@@ -100,7 +100,7 @@ public function addOption(
100100
$defaultValue = null,
101101
bool $flagOption = false
102102
): void {
103-
$this->options[$name] = new Option(
103+
$this->options[$name] = new OptionParameter(
104104
$name,
105105
$valueRequired,
106106
$defaultValue,
@@ -109,7 +109,7 @@ public function addOption(
109109
}
110110

111111
/**
112-
* @return Option[]
112+
* @return OptionParameter[]
113113
*/
114114
public function getOptions(): array
115115
{
@@ -121,11 +121,11 @@ public function addArgument(
121121
int $required = Parameter::PARAMETER_OPTIONAL,
122122
$defaultValue = null
123123
): void {
124-
$this->arguments[] = new Argument($name, $required, $defaultValue);
124+
$this->arguments[] = new ArgumentParameter($name, $required, $defaultValue);
125125
}
126126

127127
/**
128-
* @return Argument[]
128+
* @return ArgumentParameter[]
129129
*/
130130
public function getArguments(): array
131131
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php declare(strict_types=1);
22

3-
namespace Parable\Console\Command;
3+
namespace Parable\Console\Commands;
44

55
use Parable\Console\Command;
66

7-
class Help extends Command
7+
class HelpCommand extends Command
88
{
99
/**
1010
* @var string

src/Environment.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
class Environment
66
{
7-
const TERMINAL_DEFAULT_HEIGHT = 25;
8-
const TERMINAL_DEFAULT_WIDTH = 80;
7+
public const TERMINAL_DEFAULT_HEIGHT = 24;
8+
public const TERMINAL_DEFAULT_WIDTH = 80;
99

1010
public function getTerminalWidth(): int
1111
{
1212
if (!$this->isShellAvailable()) {
1313
return self::TERMINAL_DEFAULT_WIDTH;
1414
}
1515

16-
return (int)shell_exec('tput cols');
16+
return (int)shell_exec('TERM=ansi tput cols');
1717
}
1818

1919
public function getTerminalHeight(): int
@@ -22,7 +22,7 @@ public function getTerminalHeight(): int
2222
return self::TERMINAL_DEFAULT_HEIGHT;
2323
}
2424

25-
return (int)shell_exec('tput lines');
25+
return (int)shell_exec('TERM=ansi tput lines');
2626
}
2727

2828
public function isShellAvailable(): bool

src/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getKeyPress(): string
5656
$this->disableRequireReturn();
5757

5858
$input = null;
59-
while (1) {
59+
while (true) {
6060
$input = $this->getRaw();
6161
break;
6262
}

src/Parameter.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Parable\Console;
44

5-
use Parable\Console\Parameter\Argument;
6-
use Parable\Console\Parameter\Option;
5+
use Parable\Console\Parameters\ArgumentParameter;
6+
use Parable\Console\Parameters\OptionParameter;
77

88
class Parameter
99
{
@@ -44,12 +44,12 @@ class Parameter
4444
protected $arguments = [];
4545

4646
/**
47-
* @var Option[]
47+
* @var OptionParameter[]
4848
*/
4949
protected $commandOptions = [];
5050

5151
/**
52-
* @var Argument[]
52+
* @var ArgumentParameter[]
5353
*/
5454
protected $commandArguments = [];
5555

@@ -173,12 +173,12 @@ public function getCommandName(): ?string
173173
}
174174

175175
/**
176-
* @param Option[] $options
176+
* @param OptionParameter[] $options
177177
*/
178178
public function setCommandOptions(array $options): void
179179
{
180180
foreach ($options as $name => $option) {
181-
if ((!$option instanceof Option)) {
181+
if ((!$option instanceof OptionParameter)) {
182182
throw Exception::fromMessage(
183183
"Options must be instances of Parameter\\Option. %s is not.",
184184
$name
@@ -245,13 +245,13 @@ public function getOptions(): array
245245
/**
246246
* Set the arguments from a command.
247247
*
248-
* @param Argument[] $arguments
248+
* @param ArgumentParameter[] $arguments
249249
*/
250250
public function setCommandArguments(array $arguments): void
251251
{
252252
$orderedArguments = [];
253253
foreach ($arguments as $index => $argument) {
254-
if (!($argument instanceof Argument)) {
254+
if (!($argument instanceof ArgumentParameter)) {
255255
throw Exception::fromMessage(
256256
"Arguments must be instances of Parameter\\Argument. The item at index %d is not.",
257257
$index
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Parable\Console\Parameter;
3+
namespace Parable\Console\Parameters;
44

55
abstract class AbstractParameter
66
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php declare(strict_types=1);
22

3-
namespace Parable\Console\Parameter;
3+
namespace Parable\Console\Parameters;
44

55
use Parable\Console\Exception;
66
use Parable\Console\Parameter;
77

8-
class Argument extends AbstractParameter
8+
class ArgumentParameter extends AbstractParameter
99
{
1010
/**
1111
* @var int

0 commit comments

Comments
 (0)