Skip to content

Commit 1584825

Browse files
committed
docs: add setPad() method
1 parent 8d96f2d commit 1584825

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

user_guide_src/source/cli/cli_commands.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,25 @@ be familiar with when creating your own commands. It also has a :doc:`Logger </g
127127
128128
A method to show command help: (usage,arguments,description,options)
129129

130+
.. php:method:: setPad(string $item, int $max, int $extra = 2, int $indent = 0): string
131+
132+
:param string $item: The string item.
133+
:param integer $max: The max size.
134+
:param integer $extra: How many extra spaces to add at the end.
135+
:param integer $indent: The indent spaces.
136+
137+
Pads our string out so that all titles are the same length to nicely line
138+
up descriptions:
139+
140+
.. literalinclude:: cli_commands/007.php
141+
:lines: 2-
142+
130143
.. php:method:: getPad($array, $pad)
131144
132145
.. deprecated:: 4.0.5
133-
Use :php:meth:`CodeIgniter\\CLI\\setPad()` instead.
146+
Use :php:meth:`CodeIgniter\\CLI\\BaseCommand::setPad()` instead.
134147

135148
:param array $array: The $key => $value array.
136149
:param integer $pad: The pad spaces.
137150

138-
A method to calculate padding for ``$key => $value`` array output. The padding can be used to output a will formatted table in CLI:
139-
140-
.. literalinclude:: cli_commands/007.php
151+
A method to calculate padding for ``$key => $value`` array output. The padding can be used to output a will formatted table in CLI.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22

3-
$pad = $this->getPad($this->options, 6);
3+
use CodeIgniter\CLI\CLI;
4+
5+
$length = max(array_map('strlen', array_keys($this->options)));
46

57
foreach ($this->options as $option => $description) {
6-
CLI::write($tab . CLI::color(str_pad($option, $pad), 'green') . $description, 'yellow');
8+
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
79
}
810
/*
911
* Output will be:
10-
* -n Set migration namespace
11-
* -r override file
12+
* -n Set migration namespace
13+
* -g Set database group
14+
* --all Set for all namespaces, will ignore (-n) option
1215
*/

0 commit comments

Comments
 (0)