Skip to content

Commit c33dd62

Browse files
committed
docs: reflow lines within 120 columns
1 parent 9002edf commit c33dd62

230 files changed

Lines changed: 8520 additions & 10023 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎user_guide_src/source/cli/cli_commands.rst‎

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Creating Spark Commands
33
#######################
44

5-
While the ability to use Controllers via CLI like any other route is convenient, you might find times where you
6-
need a little something different. That's where Spark commands come in. They are simple classes that do not
7-
need to have routes defined, making them perfect for building tools that developers can use to make
8-
their jobs simpler, whether by handling migrations or database seeding, checking cronjob status, or even
9-
building out custom code generators for your company.
5+
While the ability to use Controllers via CLI like any other route is convenient, you might find times where you need a
6+
little something different. That's where Spark commands come in. They are simple classes that do not need to have routes
7+
defined, making them perfect for building tools that developers can use to make their jobs simpler, whether by handling
8+
migrations or database seeding, checking cronjob status, or even building out custom code generators for your company.
109

1110
.. contents::
1211
:local:
@@ -16,56 +15,60 @@ building out custom code generators for your company.
1615
Creating New Commands
1716
*********************
1817

19-
You can very easily create new commands to use in your own development. Each class must be in its own file,
20-
must extend ``CodeIgniter\CLI\BaseCommand``, and must implement the ``run()`` method.
18+
You can very easily create new commands to use in your own development. Each class must be in its own file, must extend
19+
``CodeIgniter\CLI\BaseCommand``, and must implement the ``run()`` method.
2120

22-
The following properties should be used in order to get listed in CLI commands and to add help functionality to your command:
21+
The following properties should be used in order to get listed in CLI commands and to add help functionality to your
22+
command:
2323

24-
* ``$group``: a string to describe the group the command is lumped under when listing commands. For example: ``Database``
24+
* ``$group``: a string to describe the group the command is lumped under when listing commands. For example:
25+
``Database``
2526
* ``$name``: a string to describe the command's name. For example: ``make:controller``
2627
* ``$description``: a string to describe the command. For example: ``Generates a new controller file.``
2728
* ``$usage``: a string to describe the command usage. For example: ``make:controller <name> [options]``
28-
* ``$arguments``: an array of strings to describe each command argument. For example: ``'name' => 'The controller class name.'``
29-
* ``$options``: an array of strings to describe each command option. For example: ``'--force' => 'Force overwrite existing file.'``
29+
* ``$arguments``: an array of strings to describe each command argument. For example:
30+
``'name' => 'The controller class name.'``
31+
* ``$options``: an array of strings to describe each command option. For example:
32+
``'--force' => 'Force overwrite existing file.'``
3033

3134
**Help description will be automatically generated according to the above parameters.**
3235

3336
File Location
3437
=============
3538

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
38-
a directory that you keep commands in to use in all of your project development, like **Acme/Commands**.
39+
Commands must be stored within a directory named **Commands**. However, that directory has to be located in the PSR-4
40+
namespaces so that the :doc:`Autoloader </concepts/autoloader>` can locate it. This could be in **app/Commands**, or a
41+
directory that you keep commands in to use in all of your project development, like **Acme/Commands**.
3942

40-
.. note:: When the commands are executed, the full CodeIgniter CLI environment has been loaded, making it
41-
possible to get environment information, path information, and to use any of the tools you would use when making a Controller.
43+
.. note:: When the commands are executed, the full CodeIgniter CLI environment has been loaded, making it possible to
44+
get environment information, path information, and to use any of the tools you would use when making a Controller.
4245

4346
An Example Command
4447
==================
4548

46-
Let's step through an example command whose only function is to report basic information about the application
47-
itself, for demonstration purposes. Start by creating a new file at **app/Commands/AppInfo.php**. It
48-
should contain the following code:
49+
Let's step through an example command whose only function is to report basic information about the application itself,
50+
for demonstration purposes. Start by creating a new file at **app/Commands/AppInfo.php**. It should contain the
51+
following code:
4952

5053
.. literalinclude:: cli_commands/002.php
5154

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

56-
The ``$name`` property is the name this command can be called by. The only requirement is that it must not contain
57-
a space, and all characters must be valid on the command line itself. By convention, though, commands are lowercase,
58-
with further grouping of commands being done by using a colon with the command name itself. This helps keep
59-
multiple commands from having naming collisions.
59+
The ``$name`` property is the name this command can be called by. The only requirement is that it must not contain a
60+
space, and all characters must be valid on the command line itself. By convention, though, commands are lowercase, with
61+
further grouping of commands being done by using a colon with the command name itself. This helps keep multiple commands
62+
from having naming collisions.
6063

6164
The final property, ``$description``, is a short string that is displayed in the **list** command and should describe
6265
what the command does.
6366

6467
run()
6568
-----
6669

67-
The ``run()`` method is the method that is called when the command is being run. The ``$params`` array is a list of
68-
any CLI arguments after the command name for your use. If the CLI string was:
70+
The ``run()`` method is the method that is called when the command is being run. The ``$params`` array is a list of any
71+
CLI arguments after the command name for your use. If the CLI string was:
6972

7073
.. code-block:: console
7174
@@ -87,8 +90,8 @@ See the :doc:`CLI Library </cli/cli_library>` page for detailed information.
8790
Command Termination
8891
-------------------
8992

90-
By default, the command exits with a success code of ``0``. If an error is encountered while executing a command,
91-
you can terminate the command by using the ``return`` language construct with an exit code in the ``run()`` method.
93+
By default, the command exits with a success code of ``0``. If an error is encountered while executing a command, you
94+
can terminate the command by using the ``return`` language construct with an exit code in the ``run()`` method.
9295

9396
For example, ``return EXIT_ERROR;``
9497

@@ -100,8 +103,8 @@ You can use the ``EXIT_*`` exit code constants defined in the **app/Config/Const
100103
BaseCommand
101104
***********
102105

103-
The ``BaseCommand`` class that all commands must extend has a couple of helpful utility methods that you should
104-
be familiar with when creating your own commands. It also has a :doc:`Logger </general/logging>` available at
106+
The ``BaseCommand`` class that all commands must extend has a couple of helpful utility methods that you should be
107+
familiar with when creating your own commands. It also has a :doc:`Logger </general/logging>` available at
105108
``$this->logger``.
106109

107110
.. php:namespace:: CodeIgniter\CLI
@@ -136,8 +139,7 @@ be familiar with when creating your own commands. It also has a :doc:`Logger </g
136139
:param integer $extra: How many extra spaces to add at the end.
137140
:param integer $indent: The indent spaces.
138141

139-
Pads our string out so that all titles are the same length to nicely line
140-
up descriptions:
142+
Pads our string out so that all titles are the same length to nicely line up descriptions:
141143

142144
.. literalinclude:: cli_commands/007.php
143145
:lines: 2-
@@ -150,4 +152,5 @@ be familiar with when creating your own commands. It also has a :doc:`Logger </g
150152
:param array $array: The ``$key`` => ``$value`` array.
151153
:param integer $pad: The pad spaces.
152154

153-
A method to calculate padding for ``$key => $value`` array output. The padding can be used to output a well-formatted table in CLI.
155+
A method to calculate padding for ``$key => $value`` array output. The padding can be used to output a
156+
well-formatted table in CLI.

‎user_guide_src/source/cli/cli_controllers.rst‎

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
Running Controllers via CLI
33
###########################
44

5-
As well as being called via the URL in a browser, an application's
6-
:doc:`Controllers </incoming/controllers>` can also be loaded via the command-line
7-
interface (CLI).
5+
As well as being called via the URL in a browser, an application's :doc:`Controllers </incoming/controllers>` can also
6+
be loaded via the command-line interface (CLI).
87

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` pages for detailed
12-
information.
8+
.. note:: It is recommended to use Spark Commands for CLI scripts instead of calling controllers via CLI. See the
9+
:doc:`spark_commands` and :doc:`cli_commands` pages for detailed information.
1310

1411
.. contents::
1512
:local:
@@ -22,9 +19,8 @@ Let's try it: Hello World!
2219
Create a Controller
2320
===================
2421

25-
Let's create a simple controller so you can see it in action. Using your
26-
text editor, create a file called **Tools.php**, and put the following code
27-
in it:
22+
Let's create a simple controller so you can see it in action. Using your text editor, create a file called
23+
**Tools.php**, and put the following code in it:
2824

2925
.. literalinclude:: cli_controllers/001.php
3026

@@ -37,17 +33,16 @@ Define a Route
3733

3834
If you use Auto Routing, skip this.
3935

40-
In your **app/Config/Routes.php** file you can create routes that are only accessible from
41-
the CLI as easily as you would create any other route. Instead of using the ``get()``,
42-
``post()``, or similar method, you would use the ``cli()`` method. Everything else
43-
works exactly like a normal route definition:
36+
In your **app/Config/Routes.php** file you can create routes that are only accessible from the CLI as easily as you
37+
would create any other route. Instead of using the ``get()``, ``post()``, or similar method, you would use the ``cli()``
38+
method. Everything else works exactly like a normal route definition:
4439

4540
.. literalinclude:: cli_controllers/002.php
4641

4742
For more information, see the :ref:`Routes <command-line-only-routes>` page.
4843

49-
.. warning:: If you enable :ref:`auto-routing-legacy` and place the command file in **app/Controllers**,
50-
anyone could access the command with the help of :ref:`auto-routing-legacy` via HTTP.
44+
.. warning:: If you enable :ref:`auto-routing-legacy` and place the command file in **app/Controllers**, anyone could
45+
access the command with the help of :ref:`auto-routing-legacy` via HTTP.
5146

5247
Run via CLI
5348
===========
@@ -56,8 +51,8 @@ Normally, you would visit your site using a URL similar to this::
5651

5752
example.com/index.php/tools/message/to
5853

59-
Instead, we are going to open Terminal in Mac/Linux or go to Run > "cmd"
60-
in Windows and navigate to our CodeIgniter project's web root.
54+
Instead, we are going to open Terminal in Mac/Linux or go to Run > "cmd" in Windows and navigate to our CodeIgniter
55+
project's web root.
6156

6257
.. code-block:: bash
6358
@@ -70,23 +65,21 @@ If you did it right, you should see "Hello World!" printed.
7065
7166
$ php index.php tools message "John Smith"
7267
73-
Here we are passing it an argument in the same way that URL parameters
74-
work. "John Smith" is passed as an argument and the output is::
68+
Here we are passing it an argument in the same way that URL parameters work. "John Smith" is passed as an argument and
69+
the output is::
7570

7671
Hello John Smith!
7772

7873
******************
7974
That's the Basics!
8075
******************
8176

82-
That, in a nutshell, is all there is to know about controllers on the
83-
command line. Remember that this is just a normal controller, so routing
84-
and ``_remap()`` work fine.
77+
That, in a nutshell, is all there is to know about controllers on the command line. Remember that this is just a normal
78+
controller, so routing and ``_remap()`` work fine.
8579

8680
.. note:: ``_remap()`` does not work with :ref:`auto-routing-improved`.
8781

8882
If you want to make sure the code is running via CLI, check the return value of :php:func:`is_cli()`.
8983

90-
However, CodeIgniter provides additional tools to make creating CLI-accessible
91-
scripts even more pleasant, including CLI-only routing and a library that helps
92-
you with CLI-only tools.
84+
However, CodeIgniter provides additional tools to make creating CLI-accessible scripts even more pleasant, including
85+
CLI-only routing and a library that helps you with CLI-only tools.

0 commit comments

Comments
 (0)