Skip to content

Deprecate BaseCommand::getPad and add more tests #3561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected function showError(Throwable $e)
public function showHelp()
{
CLI::write(lang('CLI.helpUsage'), 'yellow');

if (! empty($this->usage))
{
$usage = $this->usage;
Expand All @@ -184,6 +185,7 @@ public function showHelp()
$usage .= ' [arguments]';
}
}

CLI::write($this->setPad($usage, 0, 0, 2));

if (! empty($this->description))
Expand All @@ -198,6 +200,7 @@ public function showHelp()
CLI::newLine();
CLI::write(lang('CLI.helpArguments'), 'yellow');
$length = max(array_map('strlen', array_keys($this->arguments)));

foreach ($this->arguments as $argument => $description)
{
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
Expand All @@ -209,6 +212,7 @@ public function showHelp()
CLI::newLine();
CLI::write(lang('CLI.helpOptions'), 'yellow');
$length = max(array_map('strlen', array_keys($this->options)));

foreach ($this->options as $option => $description)
{
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
Expand All @@ -223,12 +227,12 @@ public function showHelp()
*
* @param string $item
* @param integer $max
* @param integer $extra // How many extra spaces to add at the end
* @param integer $extra How many extra spaces to add at the end
* @param integer $indent
*
* @return string
*/
protected function setPad(string $item, int $max, int $extra = 2, int $indent = 0): string
public function setPad(string $item, int $max, int $extra = 2, int $indent = 0): string
{
$max += $extra + $indent;

Expand All @@ -244,6 +248,10 @@ protected function setPad(string $item, int $max, int $extra = 2, int $indent =
* @param integer $pad
*
* @return integer
*
* @deprecated Use setPad() instead.
*
* @codeCoverageIgnore
*/
public function getPad(array $array, int $pad): int
{
Expand Down
1 change: 1 addition & 0 deletions tests/_support/Commands/AppInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AppInfo extends BaseCommand

protected $group = 'demo';
protected $name = 'app:info';
protected $arguments = ['draft' => 'unused'];
protected $description = 'Displays basic application information.';

public function run(array $params)
Expand Down
6 changes: 6 additions & 0 deletions tests/system/Commands/HelpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public function testHelpCommand()
$this->assertStringContainsString('command_name', $this->getBuffer());
}

public function testHelpCommandWithMissingUsage()
{
command('help app:info');
$this->assertStringContainsString('app:info [arguments]', $this->getBuffer());
}

public function testHelpCommandOnSpecificCommand()
{
command('help cache:clear');
Expand Down
4 changes: 4 additions & 0 deletions user_guide_src/source/changelogs/v4.0.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Bugs Fixed:

- Fixed a bug in ``Entity`` class where declaring class parameters was preventing data propagation to the ``attributes`` array.
- Handling for the environment variable ``encryption.key`` has changed. Previously, explicit function calls, like ``getenv('encryption.key')`` or ``env('encryption.key')`` where the value has the special prefix ``hex2bin:`` returns an automatically converted binary string. This is now changed to just return the character string with the prefix. This change was due to incompatibility with handling binary strings in environment variables on Windows platforms. However, accessing ``$key`` using ``Encryption`` class config remains unchanged and still returns a binary string.

Deprecations:

- Deprecated ``BaseCommand::getPad`` in favor of ``BaseCommand::setPad``.