Skip to content

Commit 90321e7

Browse files
authored
Merge pull request #7523 from kenjis/docs-cli
docs: update CLI
2 parents 85bfa44 + 8fc46bb commit 90321e7

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

user_guide_src/source/cli/cli_commands.rst

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ The following properties should be used in order to get listed in CLI commands a
3333
File Location
3434
=============
3535

36-
Commands must be stored within a directory named **Commands**. However, that directory can be located anywhere
37-
that the :doc:`Autoloader </concepts/autoloader>` can locate it. This could be in **app/Commands**, or
36+
Commands must be stored within a directory named **Commands**. However, that directory has to be located in the PSR-4 namespaces
37+
so that the :doc:`Autoloader </concepts/autoloader>` can locate it. This could be in **app/Commands**, or
3838
a directory that you keep commands in to use in all of your project development, like **Acme/Commands**.
3939

4040
.. note:: When the commands are executed, the full CodeIgniter CLI environment has been loaded, making it
@@ -49,7 +49,7 @@ should contain the following code:
4949

5050
.. literalinclude:: cli_commands/002.php
5151

52-
If you run the **list** command, you will see the new command listed under its own ``demo`` group. If you take
52+
If you run the **list** command, you will see the new command listed under its own ``Demo`` group. If you take
5353
a close look, you should see how this works fairly easily. The ``$group`` property simply tells it how to organize
5454
this command with all of the other commands that exist, telling it what heading to list it under.
5555

@@ -92,7 +92,7 @@ For example, ``return EXIT_ERROR;``
9292

9393
This approach can help with debugging at the system level, if the command, for example, is run via crontab.
9494

95-
You can use the ``EXIT_*`` exit code constants defined in the ``app/Config/Constants.php`` file.
95+
You can use the ``EXIT_*`` exit code constants defined in the **app/Config/Constants.php** file.
9696

9797
***********
9898
BaseCommand
@@ -127,11 +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
145+
.. deprecated:: 4.0.5
146+
Use :php:meth:`CodeIgniter\\CLI\\BaseCommand::setPad()` instead.
147+
132148
:param array $array: The $key => $value array.
133149
:param integer $pad: The pad spaces.
134150

135-
A method to calculate padding for ``$key => $value`` array output. The padding can be used to output a will formatted table in CLI:
136-
137-
.. 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.

user_guide_src/source/cli/cli_commands/002.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AppInfo extends BaseCommand
99
{
10-
protected $group = 'demo';
10+
protected $group = 'Demo';
1111
protected $name = 'app:info';
1212
protected $description = 'Displays basic application information.';
1313

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
*/

user_guide_src/source/cli/cli_controllers.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ As well as calling an application's :doc:`Controllers </incoming/controllers>`
66
via the URL in a browser they can also be loaded via the command-line
77
interface (CLI).
88

9+
.. note:: It is recommended to use Spark Commands for CLI scripts instead of
10+
calling controllers via CLI.
11+
See the :doc:`spark_commands` and :doc:`cli_commands` page for detailed
12+
information.
13+
914
.. contents::
1015
:local:
1116
:depth: 2
@@ -85,6 +90,3 @@ If you want to make sure running via CLI, check the return value of :php:func:`i
8590
However, CodeIgniter provides additional tools to make creating CLI-accessible
8691
scripts even more pleasant, include CLI-only routing, and a library that helps
8792
you with CLI-only tools.
88-
89-
.. note:: It is recommended to use Spark Commands for CLI scripts instead of calling controllers via CLI.
90-
See the :doc:`spark_commands` page for detailed information.

0 commit comments

Comments
 (0)