####################
``gitlab`` CLI usage
####################
``python-gitlab`` provides a :command:`gitlab` command-line tool to interact
with GitLab servers. It uses a configuration file to define how to connect to
the servers.
.. _cli_configuration:
Configuration
=============
Files
-----
``gitlab`` looks up 2 configuration files by default:
``/etc/python-gitlab.cfg``
System-wide configuration file
``~/.python-gitlab.cfg``
User configuration file
You can use a different configuration file with the ``--config-file`` option.
Content
-------
The configuration file uses the ``INI`` format. It contains at least a
``[global]`` section, and a specific section for each GitLab server. For
example:
.. code-block:: ini
[global]
default = somewhere
ssl_verify = true
timeout = 5
[somewhere]
url = https://some.whe.re
private_token = vTbFeqJYCY3sibBP7BZM
api_version = 3
[elsewhere]
url = http://else.whe.re:8080
private_token = CkqsjqcQSFH5FQKDccu4
timeout = 1
The ``default`` option of the ``[global]`` section defines the GitLab server to
use if no server is explicitly specified with the ``--gitlab`` CLI option.
The ``[global]`` section also defines the values for the default connection
parameters. You can override the values in each GitLab server section.
.. list-table:: Global options
:header-rows: 1
* - Option
- Possible values
- Description
* - ``ssl_verify``
- ``True``, ``False``, or a ``str``
- Verify the SSL certificate. Set to ``False`` to disable verification,
though this will create warnings. Any other value is interpreted as path
to a CA_BUNDLE file or directory with certificates of trusted CAs.
* - ``timeout``
- Integer
- Number of seconds to wait for an answer before failing.
* - ``api_version``
- ``3`` or ``4``
- The API version to use to make queries. Requires python-gitlab >= 1.3.0.
* - ``per_page``
- Integer between 1 and 100
- The number of items to return in listing queries. GitLab limits the
value at 100.
You must define the ``url`` in each GitLab server section.
.. warning::
If the GitLab server you are using redirects requests from http to https,
make sure to use the ``https://`` protocol in the ``url`` definition.
Only one of ``private_token`` or ``oauth_token`` should be defined. If neither
are defined an anonymous request will be sent to the Gitlab server, with very
limited permissions.
.. list-table:: GitLab server options
:header-rows: 1
* - Option
- Description
* - ``url``
- URL for the GitLab server
* - ``private_token``
- Your user token. Login/password is not supported. Refer to `the official
documentation`__ to learn how to obtain a token.
* - ``oauth_token``
- An Oauth token for authentication. The Gitlab server must be configured
to support this authentication method.
* - ``api_version``
- GitLab API version to use (``3`` or ``4``). Defaults to ``4`` since
version 1.3.0.
* - ``http_username``
- Username for optional HTTP authentication
* - ``http_password``
- Password for optional HTTP authentication
__ https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html
CLI
===
Objects and actions
-------------------
The ``gitlab`` command expects two mandatory arguments. The first one is the
type of object that you want to manipulate. The second is the action that you
want to perform. For example:
.. code-block:: console
$ gitlab project list
Use the ``--help`` option to list the available object types and actions:
.. code-block:: console
$ gitlab --help
$ gitlab project --help
Some actions require additional parameters. Use the ``--help`` option to
list mandatory and optional arguments for an action:
.. code-block:: console
$ gitlab project create --help
Optional arguments
------------------
Use the following optional arguments to change the behavior of ``gitlab``.
These options must be defined before the mandatory arguments.
``--verbose``, ``-v``
Outputs detail about retrieved objects. Available for legacy (default)
output only.
``--config-file``, ``-c``
Path to a configuration file.
``--gitlab``, ``-g``
ID of a GitLab server defined in the configuration file.
``--output``, ``-o``
Output format. Defaults to a custom format. Can also be ``yaml`` or ``json``.
**Notice:**
The `PyYAML package