Skip to content

Commit 5756f27

Browse files
authored
Merge pull request #8256 from cakephp/5.next-console-ux
Document console UX improvements (cakephp/cakephp#19303)
2 parents 66103f7 + 0eb9c04 commit 5756f27

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docs/en/appendices/5-4-migration-guide.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ bin/cake upgrade rector --rules cakephp54 <path/to/app/src>
2020

2121
- `BaseCommand::initialize()` is now being triggered **AFTER** arguments and options have been parsed.
2222

23+
### Console
24+
25+
Running `bin/cake` without providing a command name no longer displays the
26+
"No command provided" error message. Instead, the `help` command is shown
27+
directly.
28+
29+
The `help` command is now hidden from command listings (via
30+
`CommandHiddenInterface`). It remains accessible by running `bin/cake help` or
31+
`bin/cake help <command>`.
32+
33+
The CakePHP version header in help output is now only shown when the CakePHP
34+
version can be determined. When used outside a CakePHP application (where the
35+
version is reported as `unknown`), the header is omitted.
36+
2337
### I18n
2438

2539
- `Number::parseFloat()` now returns `null` instead of `0.0` when parsing
@@ -63,6 +77,12 @@ bin/cake upgrade rector --rules cakephp54 <path/to/app/src>
6377
without needing to pass them down from the `execute()` method. **This will be the default in CakePHP 6.0**
6478
as those arguments will be removed from the `execute()` method signature.
6579

80+
### Console
81+
82+
- Added `ConsoleHelpHeaderProviderInterface` to allow host applications to
83+
provide a custom header in console help output.
84+
See [Customizing the Help Header](../console-commands/commands#customizing-the-help-header).
85+
6686
### Controller
6787

6888
- Added `#[RequestToDto]` attribute for automatic mapping of request data to

docs/en/console-commands/commands.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,44 @@ public function console(CommandCollection $commands): CommandCollection
360360
`CommandCollection::replace()` was added.
361361
:::
362362

363+
## Customizing the Help Header
364+
365+
By default, `bin/cake help` displays a CakePHP version header at the top of
366+
command listings. When the CakePHP version cannot be determined (e.g. when the
367+
console package is used outside a CakePHP application), the header is omitted
368+
automatically.
369+
370+
You can replace the default header with your own by implementing
371+
`Cake\Core\ConsoleHelpHeaderProviderInterface` on the application class passed
372+
to `CommandRunner`:
373+
374+
```php
375+
<?php
376+
declare(strict_types=1);
377+
378+
namespace App;
379+
380+
use Cake\Core\ConsoleHelpHeaderProviderInterface;
381+
use Cake\Http\BaseApplication;
382+
383+
class Application extends BaseApplication implements ConsoleHelpHeaderProviderInterface
384+
{
385+
public function getConsoleHelpHeader(): string
386+
{
387+
return '<info>MyApp:</info> 1.4.0 (env: prod)';
388+
}
389+
}
390+
```
391+
392+
When this interface is implemented, `CommandRunner` passes the return value of
393+
`getConsoleHelpHeader()` to `HelpCommand`, replacing the default CakePHP header.
394+
Console markup tags such as `<info>` and `<comment>` are supported in the
395+
returned string.
396+
397+
::: info Added in version 5.4.0
398+
`ConsoleHelpHeaderProviderInterface` was added.
399+
:::
400+
363401
## Tree Output Helper
364402

365403
The `TreeHelper` outputs an array as a tree structure. This is useful for

0 commit comments

Comments
 (0)