From 4c4cc5dc7e639c03322046bad223c3ee353b6453 Mon Sep 17 00:00:00 2001 From: mscherer Date: Mon, 23 Mar 2026 01:30:15 +0100 Subject: [PATCH] Add TreeHelper documentation to input-output.md --- docs/en/console-commands/input-output.md | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/docs/en/console-commands/input-output.md b/docs/en/console-commands/input-output.md index c49b16bc7f..492511ffb6 100644 --- a/docs/en/console-commands/input-output.md +++ b/docs/en/console-commands/input-output.md @@ -182,6 +182,84 @@ $io->helper('Banner') The `BannerHelper` was added in 5.1 ::: +### Tree Helper + +The `TreeHelper` formats nested arrays into a tree structure with visual +connectors, similar to the output of the Unix `tree` command. This is useful +for displaying hierarchical data such as directory structures, menu trees, +or nested categories: + +```php +$data = [ + 'src' => [ + 'Controller' => [ + 'AppController.php', + 'UsersController.php', + ], + 'Model' => [ + 'Entity' => [ + 'User.php', + ], + 'Table' => [ + 'UsersTable.php', + ], + ], + ], + 'config' => [ + 'app.php', + 'routes.php', + ], +]; +$io->helper('Tree')->output($data); + +// Outputs: +// ├── src +// │ ├── Controller +// │ │ ├── AppController.php +// │ │ └── UsersController.php +// │ └── Model +// │ ├── Entity +// │ │ └── User.php +// │ └── Table +// │ └── UsersTable.php +// └── config +// ├── app.php +// └── routes.php +``` + +The helper supports various value types including strings, booleans, enums, +and closures for lazy evaluation: + +```php +$data = [ + 'debug' => true, + 'cache' => false, + 'status' => fn () => 'computed value', +]; +$io->helper('Tree')->output($data); + +// Outputs: +// ├── debug +// │ └── true +// ├── cache +// │ └── false +// └── status +// └── computed value +``` + +You can customize the indentation using the `baseIndent` and `elementIndent` +configuration options: + +```php +$io->helper('Tree') + ->setConfig('baseIndent', 4) + ->output($data); +``` + +::: info Added in version 5.3.0 +The `TreeHelper` was added in 5.3 +::: + ## Getting User Input `method` Cake\\Console\\ConsoleIo::**ask**(string $prompt, ?string $default = null): string